【问题标题】:shell script - open xterm window execute command and keep on executing scriptshell 脚本 - 打开 xterm 窗口执行命令并继续执行脚本
【发布时间】:2017-02-05 00:24:18
【问题描述】:

我正在编写一个 shell 脚本,我需要我的脚本来打开一个 xterm 窗口运行一个命令,并且在不关闭 xterm 的情况下继续执行该脚本。

代码基本上是一个巨大的菜单案例。

这是我的脚本示例

...
example() {
echo -n "thingy > "
read thingy
echo -n "thingy1> "
read thingyl
xterm -hold -e *el command*
menux  
}
...

问题:

脚本打开 xterm 执行命令并保持窗口打开但不会继续脚本,如果我按 ctrl + c 它将返回到 shell

【问题讨论】:

    标签: bash shell sh xterm


    【解决方案1】:

    这个变化

    nohup xterm -hold -e *el command* &
    

    会做你想做的。 nohup 告诉 shell 在父进程退出时不要向该子进程发送 HUP (1) 信号。 & 使xterm 命令在后台运行,以便脚本可以继续。 man nohup有详细信息。

    如果你想取消输出,那么下面会将所有输出转移到/dev/null 并且2>&1 将确保stderr 被定向到同一个地方。如果您想查看错误,请不要执行第二次重定向。

    nohup xterm -hold -e *el command* > /dev/null 2>&1 &
    

    man bash 有关于重定向的详细信息。

    【讨论】:

    • 它可以工作,但我怎样才能隐藏 nohup 消息(nohup:将输出附加到“nohup.out”)并阻止它保存.out 文件?
    • 乐于助人!
    猜你喜欢
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 2022-12-11
    • 2016-12-20
    • 1970-01-01
    相关资源
    最近更新 更多