[英]Python: how to wait for process return code using subprocess.call
I am using subprocess.call
to start my exe file with arguments this way: 我使用subprocess.call
以这种方式用参数启动我的exe文件:
def run_file(self, file_path):
subprocess.call([r'c:\file.exe', self.server_ip_address, file_path])
This works fine but now i want to wait to my return code
. 这工作正常,但现在我想等到我的return code
。
So i try to use this approach: 所以我尝试使用这种方法:
def run_file(self, file_path):
process = subprocess.call([r'c:\file.exe', self.server_ip_address, file_path])
process.wait()
print(process.returncode)
And got this error
: 并得到这个error
:
process.wait() AttributeError: 'int' object has no attribute 'wait'
Use subprocess.run
instead of subprocess.call
. 使用subprocess.run
而不是subprocess.call
。 It is blocking so no need for wait
. 它是阻塞的,所以不需要wait
。
https://docs.python.org/fr/3/library/subprocess.html https://docs.python.org/fr/3/library/subprocess.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.