[Tutor] Running another program from Python

Carlos Daniel Ruvalcaba Valenzuela clsdaniel at gmail.com
Sat Jul 21 04:08:18 CEST 2007

There is also os.system which should work in a similar way as Matlab
system. You pass a string with the command and arguments. The downside
of system is that it opens an entire shell and environment for the
program being run, you only have the return value from the

Other options can be popen if you want to feed to process with some
information or get some information from it (if everything is done
through standard input and output), but in your case you are better of
with exec or system.

Exec functions will replace your current process with the application
you want to run, this may not be what you want.

Spawn will create a subprocess, you can wait for it to finish or let
it run free knowing its process id to check it latter, it is roughly
similar to fork.

Good luck!
Carlos Daniel Ruvalcaba

On 7/20/07, Chris Smith <mc_anjo at tamu.edu> wrote:
> Howdy,
> I am working on some research. I'm trying to optimize the performance of
> an antenna. For the simulation of the antenna it would be easiest to use
> an antenna software package that I have in my lab. I know that Matlab
> can call the antenna software through a command called system. Matlab
> also uses system to pass a VB script file to the antenna software that
> tells the software what to do. However, I don't have access to Matlab in
> my lab.
> I use Python for a lot of program prototyping, and was looking through a
> Python reference book to see if there was something in there I could
> use. I ran across two functions that I thought might work. They are in
> the os module and are the different exec functions and also the spawnv
> function.
> The python program would run something like this:
> 1) optimization program comes up with initial variables to try
> 2) a VB script is generated
> 3) antenna program called and given the VB script
> 4) antenna program evaluates the antenna
> 5) results are sent back to optimization program
> 6) optimization program evaluates results and generates new variables
> 7) process from 2 on is repeated
> Would either of these two functions be what I need?
> Thanks for your help.
> Chris S.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list