Python Forum
Using a script to open multiple shells?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a script to open multiple shells?
#1
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.
Reply
#2
What do you call a shell exactly? Is it a terminal window? Can you tell us more about your OS and perhaps your terminal?
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
(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]
Reply
#4
(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.
« We can solve any problem by introducing an extra level of indirection »
Reply
#5
(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())
Reply
#6
(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()
« We can solve any problem by introducing an extra level of indirection »
Reply
#7
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?
Reply
#8
(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.
« We can solve any problem by introducing an extra level of indirection »
Reply
#9
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?
Reply
#10
(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.
« We can solve any problem by introducing an extra level of indirection »
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to generating multiple json files using python script dzgn989 4 280 May-10-2024, 03:09 PM
Last Post: deanhystad
  Power Shells vs Compile and Run programs? RockBlok 2 447 Jan-13-2024, 09:08 PM
Last Post: RockBlok
  How come my python shells are different? SuchUmami 2 657 Jul-10-2023, 08:00 PM
Last Post: snippsat
  Accessing same python script from multiple computers bigrockcrasher 1 1,775 May-25-2022, 08:35 PM
Last Post: Gribouillis
  Open and read multiple text files and match words kozaizsvemira 3 6,838 Jul-07-2021, 11:27 AM
Last Post: Larz60+
Question (solved) open multiple libre office files in libre office lucky67 5 3,455 May-29-2021, 04:54 PM
Last Post: lucky67
  Running script on multiple files Afrodizzyjack 1 2,561 May-14-2021, 10:49 PM
Last Post: Yoriz
  Python: Automated Script to Read Multiple Files in Respective Matrices Robotguy 7 4,331 Jul-03-2020, 01:34 AM
Last Post: bowlofred
  Running multiple script at the same time LoganSulpizio 1 7,145 Dec-07-2019, 04:30 PM
Last Post: Clunk_Head
  Multiple start of script dev1755 2 2,225 Sep-22-2019, 10:44 PM
Last Post: dev1755

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020