Python: How to run multiple commands in one process using popen
问题 I want to open a process and run two commands in the same process. I have : cmd1 = 'source /usr/local/../..' cmd2 = 'ls -l' final = Popen(cmd2, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) stdout, nothing = final.communicate() log = open('log', 'w') log.write(stdout) log.close() If I use popen two times, these two commands will be executed in different processes. But I want them to run in the same shell. 回答1: The commands will always be two (unix) processes, but you can