我有几份文件。一个gui和一些脚本。我怎样才能让gui打开cmd,这样我就可以从gui获取变量(文本),并用我选择的脚本将其传递给cmd?
例如,
我从我的图形用户界面( gui.py) Tonight.mp3 16 00:00:00 00:00:00 G中获得了变量的附加字符串,然后选择了所需的脚本(segmentation.py)
最后,我需要将它传递给cmd
这就是
segmentation.py Tonight.mp3 16 00:00:00 00:00:00你的建议是什么?我知道我必须使用子进程或os。
示例:
def printing():
commandline = " " + a + " " + str(chunk.get()) + " " + str(start_censorship.get()) + " " + str(end_censorship.get())
print commandline
import subprocess
subprocess.call(["C:\Users\Xavier_\Desktop\PROJECT\segmentation.py"])
## cmd = subprocess.Popen(["C:\Users\Xavier_\Desktop\PROJECT\segmentation.py" , str(a), str(chunk.get()), str(start_censorship.get()), str(end_censorship.get())], shell=True, stdout=subprocess.PIPE)
## output = cmd.communicate()
segmentButton = Button( root,text='Segment', fg="Red",command=printing)
segmentButton.pack(side=Tkinter.TOP)发布于 2014-08-02 03:14:18
使用communicate method获取输出。例如:
import subprocess
cmd = subprocess.Popen(["segmentation.py", str(a), str(chunk.get()), str(start_censorship.get()), str(start_censorship.get())], shell=True, stdout=subprocess.PIPE)
output = cmd.communicate()当标准输出设置为subprocess.PIPE时,命令的输出将从communicate()返回。
https://stackoverflow.com/questions/25086766
复制相似问题