Hello cmd is already a list after cmd.split().
So, suprocess.Popen(cmd, ....) On Mon, Feb 21, 2011 at 8:33 AM, Rita <rmorgan...@gmail.com> wrote: > Hello, > > I have been using shell for a "long" time and I decided to learn python > recently. So far I am liking it a lot especially the argparse module which > makes my programs more professional like. > > > Currently, I am rewriting my bash scripts to python so I came across a > subprocess and environment problem. > > My bash script looks like this, > > #!/usr/bin/env bash > > export JAVA_HOME="/opt/java" > export PROG="dbconn" > export JAVA_ARGS="-Xmx16g" > export ARGS="-out outdata.dat" > > $JAVA_HOME $JAVA_ARGS $PROG $ARGS > > > To convert this into python I did something like this (which isn't working > properly) > > #!/usr/bin/env python > import subprocess,os > def execute(): > try: > > cmd="$JAVA_HOME $JAVA_ARGS $PROG $ARGS" > cmd=cmd.split() > > p=subprocess.Popen([cmd],env={"JAVA_HOME":"/opt/java","PROG":"dbconn","JAVA_ARGS":"-Xmx16g","ARGS":"-out > outdata.dat"}, > stdout=subprocess.PIPE) > except OSError, e: > print >>sys.stderr," Execution failed: ",e > return p.stdout > > > So, I was wondering if this is the correct way of doing it? or is there an > alternative? > > > > > > > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Ritesh http://www.beamto.us -- http://mail.python.org/mailman/listinfo/python-list