我正在使用 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
提交
取消