Python Forum

Full Version: Using a script to open multiple shells?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have several scripts that must be run in a shell. Currently I open the shell and copy/paste the script location into the shell to run them. The problem is that I have so many to run, I was wondering if there's a way to write just one script that will run them in multiple shells individually?

I need the output in several of the shells so I have to be able to click on them and view their outputs.
What do you call a shell exactly? Is it a terminal window? Can you tell us more about your OS and perhaps your terminal?
(Mar-31-2024, 12:10 PM)Gribouillis Wrote: [ -> ]What do you call a shell exactly? Is it a terminal window? Can you tell us more about your OS and perhaps your terminal?

It is on windows. I use it to run scripts. Here is a screenshot of it:

[Image: thq91VU.png]
(Mar-31-2024, 12:53 PM)SuchUmami Wrote: [ -> ]It is on windows. I use it to run scripts. Here is a screenshot of it:
I don't have a Windows machine to try this because I don't use this OS, but you can launch a Cmd window to execute a python script, then switch to interative mode if you want, for example to launch myscript.py you could do approximately
import subprocess
proc = subprocess.Popen(['cmd.exe', '/K', 'python', '-i', 'myscript.py'])
With several similar lines, you could spawn several cmd windows at the same time, each running its own Python script and interpreter.
(Mar-31-2024, 05:39 PM)Gribouillis Wrote: [ -> ]
(Mar-31-2024, 12:53 PM)SuchUmami Wrote: [ -> ]It is on windows. I use it to run scripts. Here is a screenshot of it:
I don't have a Windows machine to try this because I don't use this OS, but you can launch a Cmd window to execute a python script, then switch to interative mode if you want, for example to launch myscript.py you could do approximately
import subprocess
proc = subprocess.Popen(['cmd.exe', '/K', 'python', '-i', 'myscript.py'])
With several similar lines, you could spawn several cmd windows at the same time, each running its own Python script and interpreter.

How would that look if I have these scripts to run:

exec(open(r'C:\Users\Chris\Python\Python Projects\websocket_bot3\websockets\websockets_spot.py').read())
exec(open(r'C:\Users\Chris\Python\Python Projects\websocket_bot3\avg_price\orderbook_data_feed.py').read())
exec(open(r'C:\Users\Chris\Python\Python Projects\websocket_bot3\avg_price\orderbook_processor_macro_flow.py').read())
exec(open(r'C:\Users\Chris\Python\Python Projects\websocket_bot3\websockets_alert.py').read())
(Mar-31-2024, 07:16 PM)SuchUmami Wrote: [ -> ]How would that look if I have these scripts to run:
Probably something like
import subprocess

scripts = [
r'C:\Users\Chris\Python\Python Projects\websocket_bot3\websockets\websockets_spot.py',
r'C:\Users\Chris\Python\Python Projects\websocket_bot3\avg_price\orderbook_data_feed.py',
r'C:\Users\Chris\Python\Python Projects\websocket_bot3\avg_price\orderbook_processor_macro_flow.py',
r'C:\Users\Chris\Python\Python Projects\websocket_bot3\websockets_alert.py']

procs = []
for script in scripts:
    proc = subprocess.Popen(['cmd.exe', '/K', 'python', '-i', script])
    procs.append(proc)
    
for proc in procs:
    proc.wait()
The problem I am having with this is that the outputs are all running through one terminal. I need to have seperate terminal windows because I need to read the outputs from the scripts. Is there a way to effectively do this?
(Mar-31-2024, 08:13 PM)SuchUmami Wrote: [ -> ]The problem I am having with this is that the outputs are all running through one terminal. I need to have seperate terminal windows because I need to read the outputs from the scripts. Is there a way to effectively do this?
Unfortunately I can't help more because I don't have a Windows machine to run the code. I hope someone else can help you. I think you could post the exact code that you are running and describe the exact effect that it has.
I use Ubuntu 22.04

If I open bash, I can type xterm, then another bash terminal opens. If I type xterm in the new window, another new window opens. The origin bash terminal is then busy, not usable.

If I type gnome-terminal in bash, another bash terminal opens. Neither terminal is busy.

Maybe you can type cmd in a cmd window to open another cmd window??

Sounds like a job for a bash script! I suppose Windows can run cmd terminal scripts?
(Apr-01-2024, 09:13 AM)Pedroski55 Wrote: [ -> ]Sounds like a job for a bash script! I suppose Windows can run cmd terminal scripts?
Python can do anything that a shell script can do.