If I run echo a; echo b in bash the result will be that both commands are run. However if I use subprocess then the first command is run, printing out the whole
echo a; echo b
You have to use shell=True in subprocess and 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