How to respond to a confirmation prompt automatically

C

Coby

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.


Thanks in advance.
 
R

Rob Wolfe

Coby said:
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
 
C

Coby

Thanks Rob.


Rob said:
Coby said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top