Prevent Gnome Terminal From Exiting After Execution

22,037

Solution 1

Try this:

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

Solution 2

alt text

Create a profile (i.e. hold), set "When command exits: Hold the terminal open" and then

$ gnome-terminal --tab --profile hold -e /usr/bin/myprog

Solution 3

Create a shell script like this:

#!/bin/bash
# myprog-wrapper.sh - runs /usr/bin/myprog and then starts a new bash session
/usr/bin/myprog
/bin/bash

Give the shell script execute permission.

Then set up your cron job to call this script instead of directly calling myprog:

gnome-terminal --tab -e "/path/to/myprog-wrapper.sh"

Replace /bin/bash with your shell of choice.

Solution 4

You could use xterm or rxvt-unicode instead of gnome-terminal, both of which have the -hold option for this purpose.

Share:
22,037

Related videos on Youtube

Cerin
Author by

Cerin

Updated on July 09, 2022

Comments

  • Cerin
    Cerin almost 2 years

    How do you prevent gnome-terminal from exiting after its given command has exited?

    I'm calling gnome-terminal from a cronjob, in order to create a terminal accessible to the user. The terminal is initially given a specific program to run. e.g.

    gnome-terminal --tab -e "/usr/bin/myprog"
    

    This works fine, except that when "myprog" exits, so does the gnome-terminal. How do I keep it running, but just drop back to a terminal prompt?

    • Aaron Altman
      Aaron Altman over 13 years
      Another discussion of the same issue: stackoverflow.com/questions/3512055/…
    • Cerin
      Cerin over 13 years
      @Ignacio, it's a common term. Google shows over 100k results for it...
    • Cerin
      Cerin over 13 years
      @Ignacio, the terms "shell" and "terminal" are generally synonymous. If your vocabulary or technical environment differs, fine. Sorry for the confusion.
  • Cerin
    Cerin over 13 years
    Very simplistic. Thanks.
  • Omar Tariq
    Omar Tariq over 7 years
    There should be some way to create a profile with hold the terminal open option set via command-line only.
  • Diego Torres Milano
    Diego Torres Milano over 7 years
    Depending on your gnome-terminal, you can use gconf or gsettings to set or get tha value of that property: gconftool-2 -g /apps/gnome-terminal/profiles/Profile0/exit_action
  • jcanizales
    jcanizales over 5 years
    For me this keeps the terminal window open, but it doesn't accept any more commands.
  • Member2017
    Member2017 over 4 years
    As of January 2020, the -e option in gnome-terminal still runs properly but throws out the following warning: << Option “-e” is deprecated and might be removed in a later version of gnome-terminal. Use “-- ” to terminate the options and put the command line to execute after it. >> Based on that information, I confirmed that you can run the following command without receiving any warning messages: <<gnome-terminal --tab -- "/bin/bash -c '/usr/bin/myprog; exec /bin/bash -i'">>
  • Agguro
    Agguro about 4 years
    Just what I need. Only the command today is a little bit changed. Just to update: gnome-terminal --tab -- /bin/bash -c '/usr/bin/nasm; exec /bin/bash -i'
  • Andrew
    Andrew almost 3 years
    Had to set execution permissions but then this worked well, thanks. Also, gnome-terminal wants us to use -- now instead of -e.