Avoid Gnome-Terminal Close After Script Execution

Prevent Gnome Terminal From Exiting After Execution

Try this:

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

How to avoid gnome-terminal close after opening it from C++?

Try

system("gnome-terminal -e \"bash -c \'echo foo; echo bar; exec bash\'\"");

The commands after bash -c needs to be in single quotes. At least it worked for me then.

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?

Title of gnome-terminal is being overridden by .bashrc in Ubuntu

The prompt set in PS1 contains screen control codes which overwrite the window title.

If you don't want the prompt to change your window title, take out the snippet which does that.

Here's a slight edit to let you set no_title_change in the calling shell. This would replace the similar snippet in your current .bashrc; the real change it that we change the variable $TERM to a slightly more complex (and slightly hacky) parameter expansion.

...

# If this is an xterm set the title to user@host:dir
# unless $no_title_change is set
case ${no_title_change-$TERM} in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

...

If you unconditionally want to remove the title-changing logic, just replace this snippet with nothing.

The use case of opening a separate terminal window for each in a set of tasks is dubious; a better practice generally is to run your tasks as background processes, each with output to a file. Then you can automate monitoring and logging for the entire scenario, and avoid silly problems like terminating a process by mistake by accidentally closing the wrong terminal window; and managing the processes remotely from multiple locations becomes feasible.

Opening multiple gnome terminals from bash and execute sudo services

Easier way is to use tmux (see) to do it.

You can do initial sudo in terminal. Then launch the tmux with the commands you need to run in parallel (you can use the sample command below and add it in script).

tmux new-session -d -s multi-run 'your command'
tmux splitw -h -p 66 'your command'
tmux splitw -h -p 50 'your command'
tmux selectp -t 1
tmux splitw -v -p 50 'your command'
tmux selectp -t 3
tmux splitw -v -p 50 'your command'
tmux attach-session -t multi-run


Related Topics



Leave a reply



Submit