python - running multiple bash commands with subprocess -


if run echo a; echo b in bash result both commands run. if use subprocess first command run, printing out whole of rest of line. code below echos a; echo b instead of a b, how run both commands?

import subprocess, shlex def subprocess_cmd(command):     process = subprocess.popen(shlex.split(command), stdout=subprocess.pipe)     proc_stdout = process.communicate()[0].strip()      print proc_stdout  subprocess_cmd("echo a; echo b") 

you have use shell=true in subprocess , no shlex.split:

def subprocess_cmd(command):     process = subprocess.popen(command,stdout=subprocess.pipe, shell=true)     proc_stdout = process.communicate()[0].strip()     print proc_stdout  subprocess_cmd('echo a; echo b') 

returns:

a b 

Comments