简体   繁体   中英

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

My code is just over 400 lines long right now and I would prefer to not be given the answer to this but rather some suggestions of what could be wrong. In my program I start a sub process with:

#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)

This is started with a tkinter button command. The program does start in the background but I . I receive the following error message in my LXTerminal when I initiate the command ( by clicking the button):

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

or depending on the command out_select:

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

Both programs do run fine as verified with an oscilloscope and I am able to return to the program and use the other button widgets. The hangup is that there is a graph in the program and I can't values being sent from an arduino over the USB port. It's not the arduino because the graph would graph a value of zero. Any suggestions on where the problem might be? If not with the few lines here then could I be doing something elsewhere?

The error message means that python executable that you are trying to start using sp = subprocess.Popen(['python',out_select]) can't find the filename that contains in out_select variable (and indeed, it is very unlikely that you have a Python script stored in a file named: 'python DACscrap.py &' literally).

Try to familiarize yourself with running external processes:

  • don't use shell=True , to run a single command. Pass a list instead
  • don't use & (Popen does not wait for the command to exit)

eg, instead of call("cmd 'arg 1' arg2 &", shell=True) , use:

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

It might be more convenient to import Python modules and call the corresponding functions instead of running the Python files as scripts using subprocess . See Call python script with input with in a python script using subprocess

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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