Hi!

I want to make a python program that runs different simple command line scripts. Right now I use os.system which works fine for running the scripts, but the problem is that the scripts sometimes halt and wait for input from the user. So my question is, how do i programmatically detect when an input has to be made, and then make that input instead of me having to make it manually?

my code like something like this...

os.system(aCommand)
os.system(anotherCommand)

aCommand and antoherCommand might stop and wait for user input which i want to make programmatically.

/Sason

There is a specialized module for this called pexpect http://www.noah.org/wiki/pexpect . It may, or may not suit your needs. The more general method is to communicate with the subprocess with pipes. For this you must use subprocess.Popen() instead of os.system(). See the documentation of module subprocess, and perhaps this blog http://www.doughellmann.com/PyMOTW/subprocess/

That seems to be exactly what I need, but it doesn't work on windows? I get a message that a critical system was not found...blabla... I also tried with cygwin, didn't work. I followed the install instructions on the website btw. The site mentiones that it doesn't work on windows but that it might work with cygwin, but no luck here.

Any suggestions? I should maybe take a look at popen. Do you know of any examples with popen that does what I want to do? I googled that earlier and couldn't find any.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.