2014-12-02 97 views
-3

我使用Python生成了一個點文件。從Python代碼執行腳本

每次生成文件時,我需要在終端中運行一個腳本,將其轉換爲pdf文件或圖像。

這是腳本:

dot -Tpdf somefile.dot -o somefile.pdf 

我想知道是否有可能在當前文件夾執行該腳本,從我的Python代碼內。

+1

的第一點[關於如何在StackOverflow上提出問題的指導原則](http://stackoverflow.com/help/how-to-ask)說,你應該尋找和研究。在你問這個問題之前,你到目前爲止還在嘗試搜索/研究什麼? – 2014-12-02 08:57:16

回答

3

os模塊允許你運行自定義腳本這樣

import os 

os.system("dot -Tpdf somefile.dot -o somefile.pdf") 

你可以找到更多信息here

0

更好地使用subprocess.Popen將有跟蹤誤差的輸出:

import subprocess 
child = subprocess.Popen(["dot -Tpdf somefile.dot -o somefile.pdf"],stdout=subprocess.PIPE, shell=True) 
output,err = child.communicate()