Reputation: 169
I need to run a series of commands in command prompt and I want to automate this process. I can run a command in command prompt using Python code:
import os
os.system("start /B start cmd.exe @cmd /k {command}")
OR
import os
import subprocess
p = subprocess.Popen(["start", "cmd", "/k", "command"], shell = True)
However, after executing a command, I cannot write another command to the same command prompt. Is there a way to do this?
The thread Calling an external command in Python is similar but I don't think it explains how to write a new command to the same command prompt after the one before finishes executing
Also, as I understand running multiple bash commands with subprocess explains how to run commands in parallel not one after each other.
Upvotes: 6
Views: 15879
Reputation: 1
you can insert the '&' symbol (or other symbols, such as '&&' for example:
p = subprocess.Popen(["start", "cmd", "/k", "cd Desktop && cd Programs"], shell = True)
Upvotes: -1