亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將“QUIT”命令傳遞給已經運行的 python 子進程

如何將“QUIT”命令傳遞給已經運行的 python 子進程

茅侃侃 2023-05-09 10:26:13
我正在使用 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')
查看完整描述

2 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

# write on the stdin out of your process 
subprocess.stdin.write('QUIT')


查看完整回答
反對 回復 2023-05-09
?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

你可以像這樣殺死進程

process.kill()


查看完整回答
反對 回復 2023-05-09
  • 2 回答
  • 0 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號