How to keep the terminal window open after it completes running? (subprocess.Call)

344 Views Asked by At

I have this code in main.py which opens a new terminal with running test.py

main.py

import subprocess

subprocess.call(['xterm', '-e', 'python test.py'])

test.py

print('HELLO')

But when the script finishes it directly closes the terminal OR when error occurs it closes the terminal, is there a way to keep the terminal open when script finishes or error occurs? (so I can see whats happening)

Thanks.

1

There are 1 best solutions below

0
Batuhan On

You can use only the input() at the end of your code but if an error occurs it will still close. So instead you can use this:

try:
  import subprocess
  subprocess.call(['xterm', '-e', 'python test.py'])
except BaseException:
  import sys
  print(sys.exc_info()[0])
  import traceback
  print(traceback.format_exc())
finally:
  input()