How to run multiple shell commands in one process?
Synthetic example: I want to create a directory and in it a subdirectory.
If I do this:
subprocess.call('mkdir dir', shell=True) subprocess.call('cd dir', shell=True) subprocess.call('mkdir subdir', shell=True) Then each command will be executed in its own subprocess, and instead of dir / subdir I will get dir and subdir on the same level.
Option
command = 'mkdir dir && cd dir && mkdir dir2' subprocess.call(command, shell=True) It doesn’t look very good, and it won’t work if I want to get returncode or stdout of each command.
Ps os.chdir () is not the same, the question is, How to run several shell commands in one process?
mkdir -p dir/subdirand run without a shell) you can’t do. - jfs