簡體   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