I have two independent scripts that need to be run all the time and display messages in the terminal: script1.py and script2
To run the scripts I use the code editor VSCode under Windows. In order to use the 2 independent terminals I create them separately and in each of them I write the command: python script1.py and python script2.py
Each time I restart, I have to do it all over again. (yes it's not hard, but I think there is a way that could run both scripts and create separate terminals in VSCode)
What I tried to do:
import subprocess
subprocess.Popen(["python", "script1.py"], creationflags=subprocess.CREATE_NEW_CONSOLE)
subprocess.Popen(["python", "script2.py"], creationflags=subprocess.CREATE_NEW_CONSOLE)
This execution option brings up two separate command-line interpreter windows. This is the usual сmd.exe so if I didn't use VSCode but ran the scripts directly through the Windows console.
import subprocess
p1 = subprocess.Popen(["python", "script1.py"], shell=True)
p2 = subprocess.Popen(["python", "script2.py"], shell=True)
This execution option outputs the result of 2 scripts into one VSCode terminal, which is inconvenient.
CodePudding user response:
In fact, the solution to the problem itself has been written in your question:
In order to use the 2 independent terminals I create them separately and in each of them I write the command: python script1.py and python script2.py
This is the most correct and safe method. Of course, if you feel troublesome, I can provide the following alternatives: