Search code examples
pythonpopen

Python Popen shell=False causes OSError: [Errno 2] No such file or directory


I am trying to run the below Popen command in OSX using shell=False:

command = "/usr/local/itms/share/iTMSTransporter.woa/iTMSTransporter -m verify -f /Volumes/Stuff/Temp/TMP_S_0_V_TV2.itmsp -u username -p password -o /Volumes/Stuff/Temp/TMP_S_0_V_TV2.itmsp/LOGFILE.txt -s provider -v eXtreme"
self.process1 = Popen(command, shell=False, stdin=PIPE)

But am getting this error:

    raise child_exception
OSError: [Errno 2] No such file or directory

What is going wrong? I also need this to function in Windows, I am aware of the directory paths, slashes, etc.


Solution

  • Popen's first argument should be a list of args. Otherwise you're telling it to find an executable named strangely. You can use shlex.split() to split correctly

    like Popen(shlex.split(command), shell=False, stdin=PIPE)

    further reading: Popen docs