gpt4 book ai didi

Python subprocess.call 和 subprocess.Popen 给我不同的输出

转载 作者:太空狗 更新时间:2023-10-30 02:00:09 25 4
gpt4 key购买 nike

使用 subprocess.call 时,输出符合预期。

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

打印结果会输出类似-533428 或 0

但是当我运行的时候

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

并打印结果,我得到空白或 stderr = "None"。

为什么不同?即使通话正常,我仍在尝试 Popen 的原因是:Python subprocess.call on sfxcl.exe not working from Windows 2003 Task Scheduler <- 我想我会试一试...

最佳答案

subprocess.Popen 返回 Popen object ,您可以使用它与进程通信并获取输出,但是 subprocess.call 只会返回进程的返回码:

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()

关于Python subprocess.call 和 subprocess.Popen 给我不同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6934696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com