1
2>>> import subprocess
3>>> cmd = [ 'echo', 'arg1', 'arg2' ]
4>>> output = subprocess.Popen( cmd, stdout=subprocess.PIPE ).communicate()[0]
5>>> print output
6arg1 arg2
7
8>>>
9
10There is a bug in using of the subprocess.PIPE. For the huge output use this:
11
12import subprocess
13import tempfile
14
15with tempfile.TemporaryFile() as tempf:
16 proc = subprocess.Popen(['echo', 'a', 'b'], stdout=tempf)
17 proc.wait()
18 tempf.seek(0)
19 print tempf.read()
20