Prevent Gnome Terminal From Exiting After Execution [duplicate]

梦想的初衷 提交于 2019-12-17 07:39:31

问题


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?


回答1:


Try this:

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



回答2:


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



回答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.




回答4:


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



来源:https://stackoverflow.com/questions/4465930/prevent-gnome-terminal-from-exiting-after-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!