例如,
我从我的GUI(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
你有什么建议?我知道我必须使用subprocess或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)
答案 0 :(得分:0)
使用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()
当stdout设置为subprocess.PIPE时,命令的输出从communicate()
返回。