views:

145

answers:

2

I don't understand what this code is doing, I'm wanting to run a command line, in Mac OS X, the code I'm using is from somebody running a Windows command line. The command still executes, but I'd like to know what the sys.platform!="win32" is for, and if I should change it to something else for Mac OS X. It seems to be saying sys.platform is not Win32, but that doesn't seem to me.

return_code = subprocess.call(str(cline), shell=(sys.platform!="win32"))
+5  A: 

Here is what this code does and does not:

  • It doesn't compile (syntax error - you need a comma between the arguments) , - not anymore.
  • It starts a subprocess and, if you are not on win32 it starts it through the shell. The "shell" argument can be True or False and sys.platform != 'win32' can also evaluate to either True or False.
shylent
Thanks, I fixed the comma. I took it out by accident when trying to format it for the question.
John
+2  A: 

Same as :

if sys.platform!="win32":
    return_code = subprocess.call(str(cline), shell=True)
else
    return_code = subprocess.call(str(cline), shell=False)

see subprocess doc (execute cline)

RC