Terminal with python

the living tribunal

Moderator
Staff member
moderator
Python:
import subprocess

# Open a terminal window
subprocess.run(["gnome-terminal"])  # For GNOME Terminal on Linux
# subprocess.run(["open", "-a", "Terminal"])  # For Terminal on macOS
# subprocess.run(["cmd", "/c", "start", "cmd"])  # For Command Prompt on Windows
 

the living tribunal

Moderator
Staff member
moderator
Advanced code
Python:
import subprocess

# Run a command in the terminal
subprocess.run(["gnome-terminal", "--", "bash", "-c", "echo Hello, World!; exec bash"])  # For GNOME Terminal on Linux
# subprocess.run(["open", "-a", "Terminal", "--args", "echo Hello, World!"])  # For Terminal on macOS
# subprocess.run(["cmd", "/c", "start", "cmd", "/k", "echo Hello, World!"])  # For Command Prompt on Windows
 
Top