繁体   English   中英

Python:如何使用subprocess.call等待进程返回代码

[英]Python: how to wait for process return code using subprocess.call

我使用subprocess.call以这种方式用参数启动我的exe文件:

def run_file(self, file_path):
    subprocess.call([r'c:\file.exe', self.server_ip_address, file_path])

这工作正常,但现在我想等到我的return code

所以我尝试使用这种方法:

def run_file(self, file_path):
    process = subprocess.call([r'c:\file.exe', self.server_ip_address, file_path])
    process.wait()
    print(process.returncode)

并得到这个error

 process.wait() AttributeError: 'int' object has no attribute 'wait' 

使用subprocess.run而不是subprocess.call 它是阻塞的,所以不需要wait
https://docs.python.org/fr/3/library/subprocess.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM