2

When I am executing an utility, blab, and it will ask yes or no for confirmation, what can I do? Thanks,

The code is as below:

proc = subprocess.Popen("blab delete {}".format(num), shell=True, stderr=subprocess.STDOUT, stdin=subprocess.STDIN) stdout_value = proc.communicate()[0] 
0

1 Answer 1

2

Popen.communicate() documentation:

If you want to send data to process's stdin using python, create the Popen object with stdin=PIPE. Similarly, to get anything other than None in the result tuple, you need to give stdout=PIPE and/or stderr=PIPE too.

from subprocess import PIPE, Popen, STDOUT process = Popen("blab delete {}".format(num), shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) output = process.communicate(input=b'yes')[0] output = output.decode('utf-8') 
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I agree. But I need to answer its question not only its output.
you could send in the answer via the same procedure, calling process.communicate(input=b'some answer') repeatedly.
It works. I always though the input is for the initial step. Out of my surprise, it can be the input for subprocess's reply

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.