繁体   English   中英

python:无法打开文件'python DACscrap.py&':[Errno 2]没有这样的文件或目录…但是可以吗?

[英]python: can't open file 'python DACscrap.py &': [Errno 2] No such file or directory… but it does?

我的代码现在只有400多行,我不希望得到这个答案,而应该给出一些错误提示。 在我的程序中,我开始了一个子过程:

#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 button命令启动的。 该程序确实在后台启动,但是我。 当我启动命令时(通过单击按钮),我在LXTerminal中收到以下错误消息:

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

或取决于命令out_select:

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

经示波器验证,这两个程序都可以正常运行,我可以返回该程序并使用其他按钮小部件。 挂起的是程序中有一个图形,我无法通过USB端口从arduino发送值。 它不是arduino,因为图形将图形化为零值。 关于问题可能出在哪里的任何建议? 如果这里没有几行内容,那我可以在别处做些什么吗?

该错误消息表示您尝试使用sp = subprocess.Popen(['python',out_select])开始的python可执行文件找不到out_select变量中包含的文件名(实际上,您不太可能拥有存储在名为'python DACscrap.py &'的文件中的Python脚本)。

尝试使自己熟悉运行外部进程:

  • 不要使用shell=True来运行单个命令。 通过列表
  • 不要使用& (Popen不等待命令退出)

例如,代替使用call("cmd 'arg 1' arg2 &", shell=True) ,请使用:

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

导入Python模块并调用相应的函数可能更方便,而不是使用subprocess将Python文件作为脚本运行。 请参见使用子流程在python脚本中使用输入调用python脚本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM