toster-cx
toster-cx

Reputation: 2387

Get bash read command prompt text from parent process

I need to automate a few bash scripts which involves answering to read prompts with y/n.

I tried to pipe stdout/stderr/stdin to a python script. Writing to stdin works but reading the prompt text from stdout/stderr doesn't for some reason? (I can read everything else that bash or sub-processes output fine.)

>>> from subprocess import Popen, PIPE
>>> proc = Popen(['bash','-c','read -r -p "Update system? [y/N] " response'],stdout=PIPE,stdin=PIPE,stderr=PIPE)
>>> proc.stdout.read(10) # <-- hangs, same with stderr, any length

I was expecting I would be able to read displayed prompt "Update system? [y/N] " somehow so I can decide what answer to pass back.

Upvotes: 1

Views: 118

Answers (1)

Related Questions