简体   繁体   中英

send yes/no during shell command executing from python script

Could you help me how to send y/n during shell command execution.

below is example code:

from subprocess import call
call(["zypper", "install", "cifs-utils"])

During execution command It will ask below

 ****someting*****
 continue? [y/n? shows all options ](y):

from python script now i need to pass "y"

I tried print "y\\n" but it does not help

OS is linux (SuSE) and Python version is 2.7

As per Evert comment I have achieved with below code

from subprocess import Popen, PIPE 
cmd = "zypper install cifs-utils"
execute = Popen(cmd.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
execute.stdin.write("y")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM