[英]How to launch a shell command on an already opened specific terminal?
I have a script ./runStart.sh
that creates a new xterm and in this xterm launch the script run.log
command. 我有一个脚本
./runStart.sh
,它创建一个新的xterm,并在此xterm中启动script run.log
命令。 Then, to finish the process I launch a script ./runStop.sh
that kills the xterm and do other stuff behind. 然后,为完成该过程,我启动了一个脚本
./runStop.sh
,该脚本将杀死xterm并进行其他处理。 The problem I have is that as I kill the process while running, there is no exit
call, so the script
command does not save the data in the actual file. 我的问题是,当我在运行时杀死进程时,没有
exit
调用,因此script
命令不会将数据保存在实际文件中。
Do you know how I could launch a command in the second script ./runStop.sh
that makes this exit
call instead of the kill <pid>
command ? 您知道如何在第二个脚本
./runStop.sh
中启动该exit
调用而不是kill <pid>
命令吗?
You can use the bash
builtin trap
to catch a signal (except KILL
and STOP
) and do the required cleanup. 您可以使用
bash
内置trap
捕获信号( KILL
和STOP
除外)并进行所需的清除。
For example, here i am catching the pseudo signal EXIT
that would cover any signal that would make the shell to exit: 例如,在这里我捕获了伪信号
EXIT
,该伪信号将覆盖将使外壳退出的任何信号:
xterm -e '/bin/bash' -c 'trap "echo ok >/tmp/foobar" EXIT; sleep 5'
sleep 5
is my main task and echo ok >/tmp/foobar
is cleanup task upon exiting. sleep 5
是我的主要任务,退出时echo ok >/tmp/foobar
是清理任务。
Alternately if are sure about the signal to be sent/received eg HUP
, INT
, you can trap those directly. 或者,如果确定要发送/接收的信号,例如
HUP
, INT
,则可以直接捕获它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.