AndrewGrant
AndrewGrant

Reputation: 808

Python system call that works on windows and linux

I have a strange issue, that I cannot seem to resolve

from subprocess import PIPE, Popen

exeLocation = "../Engine.exe"

# Works on windows
proc = Popen([exeLocation, arg1, arg2],stdout=PIPE,shell=True])
(out,err) = proc.communicate()

# Works on Linux
proc = Popen(" ".join([exeLocation, arg1, arg2]),stdout=PIPE,shell=True])
(out,err) = proc.communicate()

For some reason, a '..' is not a command error thrown if you run the linux version on windows.

For some reason the command passed of "exeLocation arg1 arg2" wont work in linux, using the windows version.

I need a way to perform this operation on both platforms, using the same code.

Upvotes: 0

Views: 247

Answers (1)

jfs
jfs

Reputation: 414655

The portable code should use a list argument (drop shell=True) or it should pass the command as a string if shell=True is required.

Don't use relative paths such as ../: either pass the absolute path (including the file extension) or rely on PATH envvar and use something like: program = 'engine'.

Upvotes: 1

Related Questions