How to respond to a confirmation prompt automatically

Rob Wolfe rw at smsnet.pl
Fri Jan 12 23:35:03 CET 2007


"Coby" <firefoxxer at gmail.com> writes:

> Just to give you some background about my problem:
>
> I execute os.system(command), where command is a string.
>
> On the command line in windows, I get:
>
> "Continue, and unload these objects? [no]"
>
> I need to respond 'y' to continue, but I am uncertain on how to output
> the 'y' automatically.

You need to use pipe.

1.

p = os.popen(command, "w")
p.write("y\n")

http://docs.python.org/lib/os-newstreams.html#os-newstreams

2.

from subprocess import Popen, PIPE
p = Popen(command, shell=True, stdin=PIPE)
p.stdin.write("y\n")

http://docs.python.org/lib/module-subprocess.html

-- 
HTH,
Rob



More information about the Python-list mailing list