Prevent Gnome Terminal from Exiting After Execution

Prevent Gnome Terminal From Exiting After Execution

Try this:

gnome-terminal --tab -- "/bin/bash -c '/usr/bin/myprog; exec /bin/bash -i'"

How do I use python -i 'script.py' without closing terminal window after quitting interpreter?

As per your comment, you launch the gnome-terminal with python as the main process. Per default, gnome-terminal closes itself, if the shell process, in your case python, exits. You have two options.

Modify the beahviour of gnome-terminal

In the settings for gnome-terminal navigate to your used profile (left sidebar), then to the 4th tab (named something like Command). In the bottom drowpdown menu (named something like When command exits) you can set gnome-terminal to keep running when the command exits.

However, this is most likely not what you want, since you'll be left with a non-functional terminal window without a running shell.

Wrap your command in a shell process

If you want an interactive shell after python exits, you need to start one in the first place. To make it fall back to a shell, you can tell it to execute the shell again, after python exits:

gnome-terminal --full-screen -- /bin/bash -c "python3 -i path/to/script.py; bash"

See also: How to invoke bash, run commands inside the new shell, and then give control back to user?

Bash: Script Calling Gnome Terminal Leads To Child Process Error?

-x and --command are incorrect/obsolete options, try this :

sudo gnome-terminal --window --wait --tab --active --geometry=120X60 \
--title="$1" --working-directory="$code_directory" -- "$file_path"

To keep the terminal window open :

sudo gnome-terminal --window --wait --tab --active --geometry=120X60 \
--title="$1" --working-directory="$code_directory"\
-- bash -c "$file_path; exec bash"


Related Topics



Leave a reply



Submit