问题
I'm running python 2.6. I'm getting the subprocess throws [Errno 2] No such file or directory only when I run the script via ssh.
For example, if I run the script manually on the machine, there are no errors, but if I do ssh hostname script.py --host hostname
it generates the error and tells me that File "/usr/lib64/python2.6/subprocess.py is missing, but that's not true as both servers have that file.
I've written the subprocess call like this:
p4 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
The command just contains a list.
Any ideas why it works locally, but not remotely?
回答1:
The solution for this was to simply have the command set to the absolute path, for example, instead of mke2fs, I needed /sbin/mke2fs.
来源:https://stackoverflow.com/questions/30938429/python-subprocess-throws-errno-2-no-such-file-or-directory-error-generated-on