[英]send yes/no during shell command executing from python script
您能幫我如何在執行Shell命令期間發送y / n嗎?
下面是示例代碼:
from subprocess import call
call(["zypper", "install", "cifs-utils"])
在執行命令期間它將在下面詢問
****someting*****
continue? [y/n? shows all options ](y):
從python腳本現在我需要傳遞“ y”
我嘗試打印“ y \\ n”,但沒有幫助
操作系統是Linux(SuSE),Python版本是2.7
根據我的Evert評論,我用下面的代碼實現了
from subprocess import Popen, PIPE
cmd = "zypper install cifs-utils"
execute = Popen(cmd.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
execute.stdin.write("y")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.