Python Subprocess - Run A Second Command In The New Command Prompt Created
Python 3.6.7, Windows 7/10 I have to run two commands one after the other using subprocess.run. The first command opens a new command prompt. The next command needs to be run in th
Solution 1:
It depends on which commands you want to run but I think one solution would be to create a batch script running those two commands one after the other.
Or you could try to write the second command on the stdin of your first subprocess with something like :
pipe = subprocess.Popen('first command', shell=True, stdin=subprocess.PIPE)
pipe.communicate(input='second command')
but I am not sure that would works since the process will finish right after the first command termination ?
EDIT: add indentation
Solution 2:
Why don't you pipe the commands?
subprocess.run('first command | second command', shell=True)
Post a Comment for "Python Subprocess - Run A Second Command In The New Command Prompt Created"