2016-05-12 21 views
-5

我必须重新编写在Linux中编写的代码,该代码用于检查文件夹中的新.txt文档,然后将它们转换为.pdf并通过电子邮件发送将该文档置于新.pdf中的用户。我对这种编码语言不是很熟悉,因此不知道更改代码所需的关键字,以便用python重写。改变了一些词语来保护身份。对格式化,第一篇文章抱歉。 这是原来的代码:将.txt重新写入Linux服务器的.pdf代码以在Windows Enterprise 2008服务器上工作

#This script checks the shares drive for "letters": txt files containing the contents of a letter to a customer. 
#If it finds a letter, it uses a python script to convert that letter to a pdf, and then overlay that pdf on the 


oldDir=`pwd` 
sPath="/harris/SCRIPTS/regular_reports/txt2pdf" 
iPath="/pdrive/letter2pdf/input" 
oPath="/sdrive/letter2pdf/output" 
processingPath="/harris/SCRIPTS/regular_reports/txt2pdf/processing" 

cd "$iPath" 

echo "Checking for $iPath/*.txt" 

function run { 
#Change to the input directory so I can use relative paths 
cd "$iPath" 
if ls -1 *.txt; then 
    #Get a list of all *.txt files in the input directory 
    list=`ls -1 *.txt` 
    #Loop through all files, processing one at a time 
    for file in $list; do 
     cd "$iPath" 
     #Move the input file to a temporary location for processing 
     mv ${file} "${processingPath}/" 
     cd "$processingPath" 
     echo ${file} 
     #The new file will be named the same, just with a .pdf extension 
     newfile=`echo "$file" | sed 's\.txt\.pdf\'` 
     #The email address to use is the file name (without extension), followed by @example.ca, so remove the extension. 
     email=`echo "$file" | sed 's|.txt||'` 
     echo "the new file is $newfile" 
     #Convert the text file to a PDF 
     python $sPath/txt2pdf.py $file 
     #Overlay the text on the letterhead 
     python $sPath/overlay.py "${file}.pdf" "${newfile}" 
     echo "[email protected]" 
     #The name of the file to email: 
     emailFile=`date '+%Y%m%d%H%M%S'`"Example.pdf" 
     outputFile="$oPath/`date '+%Y%m%d%H%M%S'`${newfile}" 
     cp "${newfile}" "$emailFile" 
     #If it's a new month, a folder will be created to hold the month's outputs 
     mkdir "$oPath/`date '+%B_%Y'`" 
     #Copy the file to the output (archival) directory 
     cp "${newfile}" "$oPath/`date '+%B_%Y'`/`date '+%Y%m%d%H%M%S'`${newfile}" 
#Remove the file 
    rm "${newfile}" 
mv "${newfile}" "$oPath/`date '+%Y%m%d%H%M%S'`${newfile}" 
#Send the email 
echo "Letter is attached." | mutt -e "my_hdr From:Letter2PDF<[email protected]>" -a "$emailFile" -s "Letter" "${email}@veridian.on.ca" 
    mv "${newfile}" "$oPath/`date '+%Y%m%d%H%M%S'`${newfile}" 
    #Remove the files we no longer need 
    rm "$file" "${file}.pdf" 
    done 
    else 
    echo "no valid files" 
    fi 
    cd "$oldDir" 
} 


    run 
    rm $processingPath/*.pdf 
+1

堆栈溢出并不是真的让人们为你做你的工作的地方。这是一个要求特定编程问题的地方。那么告诉我们当你在Windows服务器上运行这个文件时会发生什么?什么是你得到的错误信息?询问如何解决您遇到的特定问题,并获得有用答案。 – aychedee

+0

我不知道它写的代码,这就是为什么我发了帖子,看起来像我会从头开始。抱歉。 – jhan11

+0

没关系!问一个关于堆栈溢出的问题有一些技巧。祝你的项目好运。 – aychedee

回答

1

告诉你的代码是不是Python的(尽管它调用了几个Python脚本,其内容还没有显示的)。

这些是Unix/Linux命令,必须由一些等效的Windows命令替换。除非你安装一个Unix兼容工具包(Cygwin?),否则这可能很困难

要做翻译,你需要对bash shell编程,unix命令,基本awk,手册页和蟒蛇编程

+0

对不起,我没有指定,它是以前在/ for Linux中编写的代码,我试图在python中重新编写它以用于新的Windows服务器。我不知道它写的代码,这就是为什么我发布这篇文章,看起来像我将从头开始。 – jhan11

+0

@ jhan11:因为它所做的事情相当明显,所以你应该毫不费力地重写它。如果你在Win10上,你可以[安装微软的bash端口](http://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows- 10 /)(适用于Windows的Linux子系统) - 但你不是。 – RedGrittyBrick

+0

会不会安装cygwin有同样的效果? – jhan11

相关问题