[英]How to pass the 'QUIT' command to the already running python sub process
我正在使用 python 并调用子进程并逐行读出 put ,它工作正常,如下所示。
process = subprocess.Popen(['jdebug', 'File.tgz'],
stdout=subprocess.PIPE,
universal_newlines=True)
while True:
output = process.stdout.readline()
print(output.strip())
return_code = process.poll()
print( return_code)
if "lastdata" in str(output): <- How to send 'bt' and 'quit' command at this point and read the response back.
process.communicate('bt')
process.communicate('quit')
if return_code is not None:
# Process has finished, read rest of the output
for output in process.stdout.readlines():
print(output.strip())
break
我想向“jdebug”进程发出“bt”和“quit”命令,当上述条件为真时退出该进程。 由于 jdebug 进程不会返回控制权,并且 python 程序需要显式发出“退出”命令才能恢复控制权。
想知道如何做到这一点?
我发送这个值: process.stdin.write('bt\n') process.stdin.write('quit\n')
# write on the stdin out of your process
subprocess.stdin.write('QUIT')
你可以像这样杀死进程
process.kill()
您可以设置一个全局 boolean 变量,而不是将字符串发送到子进程,您可以使用此变量完成您的进程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.