Calling external program from within python

Diez B. Roggisch deets at nospam.web.de
Fri Jul 25 10:28:20 EDT 2008


Mike Driscoll schrieb:
> On Jul 25, 7:56 am, Emmanouil Angelakis <angel... at mpifr-bonn.mpg.de>
> wrote:
>> Hi,
>>
>> I am tryiong to do something obviously trivial such as:
>> I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the  "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard.
>>
>> How do I do that?
>>
>> thanks i advance!
>> manolis
> 
> There are probably many ways to do this. I would recommend checking
> out the subprocess module and see if it does what you want.

This will only work if the program can be fully controlled by 
commandline arguments. If interaction is required, the OP might consider 
using pexpect.


> Or you
> could learn a little Tkinter or wxPython and use that to get the
> user's variable. Or you could even do it via the command line using
> the "raw_input" command.

I fail to see how *gathering* input (regardless of the method) solves 
the problem of *passing* input to a subprocess.

Diez



More information about the Python-list mailing list