Python subprocess.call and subprocess.Popen gives me different results

When using subprocess.call, the output is what is expected.

result = subprocess.call([securefx, '/NoPrompt', '/Q', '/RetryCount', retries, '/RetryDelay', '1', '/Log', sfxLogFile, '/List', '/S', session]) 

Printing the result will output something like -533428 or 0

But when I started

 args = [securefx, '/NoPrompt', '/Q', '/RetryCount', retries, '/RetryDelay', '1', '/Log', sfxLogFile, '/List', '/S', session] process = subprocess.Popen(args, stdout=subprocess.PIPE) result = process.communicate()[0] 

and print the result, I get empty or else stderr = "None".

Why are they different? The reason I try to execute Popen, even though the call works, is this: Python subprocess.call on sfxcl.exe does not work from the Windows 2003 Task Scheduler <- I thought I'd go from it ...

+4
source share
1 answer

subprocess.Popen returns a Popen object that you can use to communicate with the process and get the output, however subprocess.call will only return the return code for the process:

  subprocess.call (* popenargs, ** kwargs)
   Run command with arguments.  Wait for command to complete, then return the returncode attribute.

So subprocess.call is basically equivalent to the following code and exists only for convenience:

 def call(*popenargs, **kwargs): p = subprocess.Popen(*popenargs, **kwargs) return p.wait() 
+10
source

All Articles