2016-03-04 50 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

相關問題