从Python代码执行脚本
问题描述:
我使用Python生成了一个点文件。从Python代码执行脚本
每次生成文件时,我需要在终端中运行一个脚本,将其转换为pdf文件或图像。
这是脚本:
dot -Tpdf somefile.dot -o somefile.pdf
我想知道是否有可能在当前文件夹执行该脚本,从我的Python代码内。
答
更好地使用subprocess.Popen
将有跟踪误差的输出:
import subprocess
child = subprocess.Popen(["dot -Tpdf somefile.dot -o somefile.pdf"],stdout=subprocess.PIPE, shell=True)
output,err = child.communicate()
的第一点[关于如何在*上提出问题的指导原则](http://*.com/help/how-to-ask)说,你应该寻找和研究。在你问这个问题之前,你到目前为止还在尝试搜索/研究什么? – 2014-12-02 08:57:16