HOWTO execute an external program?

Patrick Guio patricg at fys.uio.no
Thu Nov 8 13:08:34 CET 2001


On Thu, 8 Nov 2001, Emile van Sebille wrote:

> > I would like to use python as a scripting language to run my simulation
> > code. I would like to know how do I do that ?
>
> There are lots of ways.  If you provide more details of where you're
> starting from and what you want to get done I'm sure you'll get responses to
> help you get there.

I want to run my simulation code in a loop with different argument values,
I now use a bourne shell script like

timelogger="/usr/bin/time -p
execname="picsim"
for B in 0.1 0.2 0.3 0.4 0.5 0.6 ; do
  if [ ! -f $dir/${filename}B$B.hdf ] ; then
    command="$execname bvector=0,$B -o $filename.hdf -i $conffile"
    ($timelogger $command > run.log) > run.cmd 2>&1
    ....
  fi
done

Now I need to calculate, at each iteration, new values of several other
arguments and it looks like python is nice to do maths operations.
So what I need is

iteration loop
  calculate argument values val1,val2,...valn
  command="myprog -arg1="+val1+ " -arg2="+val2....
  execute the command AND time it AND log the stdout and stderr of running
it
end

I hope it helps you understanding the problem.
Sincerely
Patrick





More information about the Python-list mailing list