Python subprocess.call and subprocess.Popen giving me different outputs
When using subprocess.call, the output is what is expected.
result = subprocess.call([securefx, '/NoPrompt', '/Q', '/RetryCount', retries,
'/RetryDela开发者_开发问答y', '1', '/Log', sfxLogFile, '/List', '/S', session])
Printing the result will output something like -533428 or 0
But when I run
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 blank or otherwise stderr = "None".
Why are they different? The reason I'm trying Popen even though call is working is because of this: Python subprocess.call on sfxcl.exe not working from Windows 2003 Task Scheduler <- thought I'd give it a go...
subprocess.Popen
returns a Popen object, which you can use to communicate with the process and get output, however subprocess.call
will only return the return code of 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 only exists for convenience:
def call(*popenargs, **kwargs):
p = subprocess.Popen(*popenargs, **kwargs)
return p.wait()
精彩评论