from subprocess import *
c = 'command 1 && command 2 && command 3'
# for instance: c = 'dir && cd C:\\ && dir'
handle = Popen(c, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True)
print handle.stdout.read()
handle.flush()
If i'm not mistaken, the commands will be executed over a "session" and thus keeping whatever niformation you need in between the commands.
More correctly, using shell=True (from what i've been tought) is that it's supposed to be used if given a string of commands rather than a list. If you'd like to use a list suggestions are to do as follows:
import shlex
c = shlex.split("program -w ith -a 'quoted argument'")
handle = Popen(c, stdout=PIPE, stderr=PIPE, stdin=PIPE)
print handle.stdout.read()
And then catch the output, Or you could work with a open stream and use handle.stdin.write() but it's a bit tricky.
Unless you only want to execute, read and die, .communicate() is perfect, or just .check_output(<cmd>)
Good information n how Popen works can be found here (altho different topic): python subprocess stdin.write a string error 22 invalid argument
Solution
Anyway, this should work (you have to redirect STDIN and STDOUT):
from subprocess import *
c = 'gdaltransform -s_srs \'+proj=lcc +lat_1=34.03333333333333 +lat_2=35.46666666666667 +lat_0=33.5 +lon_0=-118 +x_0=2000000 +y_0=500000 +ellps=GRS80 +units=m +no_defs\' -t_srs epsg:4326 \n' + str(x) + ' ' + str(y) + '\n'
handle = Popen(c, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True)
print handle.stdout.read()
handle.flush()