0

I'm trying to launch a python program in a new window within another python program. However, the window opens to just a command prompt and the new program doesn't launch. I've searched for this answer and can't find anything that pulls it off. What am I doing wrong here?

Popen(["gnome-terminal", "-e", "'python3 ~/Desktop/subprocessLaunch.py'"], shell=True)
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Joseph
  • 301
  • 3
  • 13
  • Try `["python3", "~/Desktop/subprocessLaunch.py"]` – Olvin Roght Sep 11 '22 at 15:19
  • 1
    @OlvinRoght, that won't expand the tilde so the file won't be found. – Charles Duffy Sep 11 '22 at 15:20
  • That didn't open a new window either, it just opened python3 command prompt in the same terminal – Joseph Sep 11 '22 at 15:22
  • 1
    @Joseph, with `shell=True` and a list, only the first entry in that list is source code for the shell to run. All other entries are arguments to be passed to that shell. Also, don't put syntactic quotes in literal data. – Charles Duffy Sep 11 '22 at 15:22
  • That is to say: If you switch to `shell=False`, you don't need the single quotes inside the Python double quotes. (You don't need them with `shell=True` either, for that matter). – Charles Duffy Sep 11 '22 at 15:25
  • Ok I'll try that, but, I'm not sure that fixes the overall problem. – Joseph Sep 11 '22 at 15:26
  • If your gnome-terminal usage is correct, fixing those two things together will solve the overall problem. – Charles Duffy Sep 11 '22 at 15:28
  • ...that "if" is important, because gnome-terminal usage has changed over time, and the old usage may not work on a new release, so you need to check the manual for the specific version you have at hand. The modern usage is described at https://stackoverflow.com/a/69875728/14122, as `subprocess.call(['gnome-terminal', "--", "python3", "server_deployment.py"])` -- but because, as I described above, you don't get tilde expansion for things that aren't parsed as shell source code, you may need to run `~/Desktop/subprocessLaunch.py` through `os.path.expanduser()`. – Charles Duffy Sep 11 '22 at 15:30
  • So you'd get something like `Popen(['gnome-terminal', '--', 'python3', os.path.expanduser('~/Desktop/subprocessLaunch.py')])`; where the `os.path.expanduser()` replaces the `~` with something like `/home/Joseph`. – Charles Duffy Sep 11 '22 at 15:32

0 Answers0