我正在使用 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”和“退出”命令以退出进程。由于 jdebug 进程不返回控制权,python 程序需要显式发出“退出”命令以取回控制权。想知道如何做到这一点?我发送这个值:process.stdin.write('bt\n') process.stdin.write('quit\n')
添加回答
举报
0/150
提交
取消