Calling external program from within python

Diez B. Roggisch deets at nospam.web.de
Fri Jul 25 12:17:44 EDT 2008


Mike Driscoll schrieb:
> On Jul 25, 9:28 am, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>> 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
> 
> My understanding of the OP's request was that "tsys2list" was a custom
> script of some sort that gathered info from the user, so I wanted to
> know why he didn't just skip calling it and write something in Tkinter
> or wxPython or even via the CLI instead.
> 
> I'm probably just not understanding something.

The program is doing some work, and needs to be told what actually to 
do. It does so by asking the user, sure. But then it *works*. I think 
that's pretty clear from

"""
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.
"""

So replacing it with something that asks the same questions leaves us 
with the work undone...


Diez



More information about the Python-list mailing list