2016-03-04 26 views
0

我的代码现在刚刚超过400行,我宁愿不给予这个答案,而是对可能出错的一些建议。在我的程序中,我开始一个子过程:python:无法打开文件'python DACscrap.py&':[Errno 2]没有这样的文件或目录...但它呢?

#out_select is a variable that defaults to the AD9850 control program 
#and is switched to the sinetable program with the valve_select command. 
subprocess.call(out_select, shell=True) 
#The following lines are used to find the PID of the program used for output 
#and save it for the stop command to kill that PID. 
sp = subprocess.Popen(['python',out_select]) 
end_sine = int(sp.pid)-1 
print end_sine 
#end = str(end_sine) 

这是用tkinter按钮命令启动的。该程序确实在后台开始,但我。我收到我的LXTerminal以下错误消息时我启动命令(通过点击按钮):为验证与

python: can't open file 'sudo python AD9850_GUI.py &': [Errno 2] No such file or directory 

两个程序都运行良好:

python: can't open file 'python DACscrap.py &': [Errno 2] No such file or directory 

或者根据命令out_select示波器,我可以返回到程序并使用其他按钮小部件。挂断是程序中有一个图形,我不能通过USB端口从arduino发送值。这不是arduino,因为图表会绘制一个零值。有关问题可能出在哪里的任何建议?如果这里没有几行,那么我可以在其他地方做点什么吗?

回答

1

错误消息意味着python的可执行文件,您要开始使用sp = subprocess.Popen(['python',out_select])无法找到,在out_select变量包含(实际上文件名,这是不太可能,你必须存储在一个文件名为Python脚本:字面意义上的'python DACscrap.py &')。

尝试熟悉运行的外部进程:

  • 不使用shell=True,运行一个命令。传递一个列表,而不是
  • 不使用&(POPEN不等待命令退出),而不是call("cmd 'arg 1' arg2 &", shell=True)

例如,使用:

p = Popen(['cmd', 'arg 1', 'arg2']) 
# ... do something else 
p.wait() 

这可能是更方便导入Python模块并调用相应的函数,而不是使用subprocess作为脚本运行Python文件。见Call python script with input with in a python script using subprocess

相关问题