2013-04-01 109 views
0

執行交互shell代碼使用我在python

executeCode = 'pdflatex -shell-escape "' + packageName + '.tex"' 
result = os.system(executeCode) 

的LaTeX的文檔可以但是有一個錯誤調用pdflatex蟒蛇,在這種情況下pdflatex請求鍵盤輸入。 對於python,這與無限循環相同。在PyScripter內,我甚至無法停止python。我必須殺死pdflatex。

現在我需要兩樣東西 1.我想看看pdflatex 2的輸出,我需要在控制檯上pdflatex互動

我怎麼能這樣做?

回答

0

如果您使用--interaction nonstopmode選項,pdflatex不會停止並要求輸入。

使用subprocess模塊爲您提供了有關如何處理過程的更多選項。

subprocess.call(['pdflatex', '--interaction', 'nonstopmode', '-shell-escape', packageName + '.tex']) 

您可以使用stdoutstderr選擇那些輸出重定向到一個管道或文件。

如果要捕獲程序的輸出,請改用subprocess.check_output()