简体   繁体   English

如何使Shell脚本中的exec命令在不同的进程中运行?

[英]How to make exec command in shell script run in different process?

I'm working with this GUI application, GTKWave, that has a startup script, gtkwave , which I've added to my system path. 我正在使用这个GUI应用程序GTKWave,它具有一个启动脚本gtkwave ,我已将其添加到系统路径中。 At the very end of said script, there is this line: 在上述脚本的最后,有以下一行:

$EXEC "$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS

where $EXEC=exec 其中$EXEC=exec

My problem is that given how exec works, my terminal is "hijacked" by the GUI process, meaning I can't run any more commands until I close the window, which is not ideal. 我的问题是,鉴于exec工作方式,我的终端被GUI进程“劫持”,这意味着在关闭窗口之前,我无法再运行任何命令,这是不理想的。

I currently got around this by putting this function in my .bash_profile : 我目前通过将此函数放在.bash_profile解决此问题:

function run-gtkwave ( ) { nohup gtkwave $1 &>/dev/null & }

While this works, it makes it hard to pass arguments to gtkwave . 虽然这样做有效,但很难将参数传递给gtkwave Ideally, I could do a form right before that exec command, but I'm not sure how to do that in bash. 理想情况下,我可以在该exec命令之前执行一个表单,但是我不确定如何在bash中执行该操作。 I know that the & character should do that, but 我知道&字符应该这样做,但是

$EXEC "$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS &

doesn't cut it, and neither does 不削减,也没有

"$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS &

or 要么

("$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS) &

How do I modify this line to run the application in its own process? 如何修改此行以在其自己的进程中运行应用程序?

You can make your run-gtkwave function pass arguments to gtkwave by changing the definition to: 通过将定义更改为,可以使run-gtkwave函数将参数传递给gtkwave

function run-gtkwave { nohup gtkwave "$@" &>/dev/null & }

Since using nohup and output redirection stops the terminal being "hijacked", you might be able to fix the problem in gtkwave by doing the nohup redirection and the output redirection there. 由于使用nohup和输出重定向可以防止终端被“劫持”,因此您可以通过执行nohup重定向和在那里的输出重定向来解决gtkwave的问题。 (If standard input is a terminal, nohup redirects it from /dev/null .) One possibility is: (如果标准输入是终端,则nohup/dev/null重定向它。)一种可能是:

"$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS </dev/null &>/dev/null &

(I've omitted the $EXEC because I can't see any point in using exec and & together.) (我省略了$EXEC因为在同时使用exec&时看不到任何意义。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM