1

I am trying to open a new terminal through a python script and run a linux command in it using subprocess().

This is the code I used:

import subprocess

command="subprocess.run('ls')"

subprocess.Popen(['gnome-terminal', '--', 'bash', '-c', command], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

It launches a terminal but then closes immediately after, and I cannot find if the command got executed at all.

Jay Shaw
  • 11
  • 1
  • Does this answer your question? https://stackoverflow.com/a/9327923/19835828 – no_modules Nov 22 '22 at 11:25
  • @no_modules No, it launches the subprocess inside the same terminal. – Jay Shaw Nov 22 '22 at 11:36
  • If you activate an input prompt for the user between each command, does it stay open? – no_modules Nov 22 '22 at 12:59
  • Should `command="subprocess.run('ls')"` just be `command="ls"`? In this example you could try something like `command="ls;read"`. So it runs the first command then waits for user input which should keep it open. – kconsiglio Nov 22 '22 at 16:34

0 Answers0