Linux 将按键发送到后台应用程序
如果我有一个命令行程序作为与命令行交互的后台线程(AKA with./program&)执行,我如何向它发送命令?有没有一种方法(比如,使用“管道”)发送字符,就好像它们是在命令行上输入的一样 简化的命令行示例: 无&(正常情况): 用&(我的案子!): ps-e | grep测试程序显示它仍在运行,但现在不能在“kill”命令之外终止 理想情况如下:Linux 将按键发送到后台应用程序,linux,command-line,send,Linux,Command Line,Send,如果我有一个命令行程序作为与命令行交互的后台线程(AKA with./program&)执行,我如何向它发送命令?有没有一种方法(比如,使用“管道”)发送字符,就好像它们是在命令行上输入的一样 简化的命令行示例: 无&(正常情况): 用&(我的案子!): ps-e | grep测试程序显示它仍在运行,但现在不能在“kill”命令之外终止 理想情况如下: ~/home/temp> ./testprogram & ~/home/temp> Welcome to Testprog
~/home/temp> ./testprogram &
~/home/temp> Welcome to Testprogram. Enter command:
~/home/temp> quit
~/home/temp> Command not found.
~/home/temp> quit | /cat/proc/testprogram
~/home/temp> Goodbye!
具体如何操作?您可以使用fg将程序带回来:
~/home/temp> ./testprogram &
Welcome to Testprogram. Enter command:
~/home/temp> ls /tmp # do whatever else you want to do on the shell
# ... later
~/home/temp> jobs # what was running?
[1]+ Running ./testprogram &
~/home/temp> fg # Brings testprogram to foreground, does not re-prompt
quit
Goodbye!
~/home/temp>
如果您有多个后台作业,则可以使用“fg%1”“fg%2”选择要对其进行前台处理的作业
注意:通过停止(Ctrl-z)作业,然后在shell提示下键入bg,可以将前景作业放回后台
~/home/temp> ./testprogram &
~/home/temp> Welcome to Testprogram. Enter command:
~/home/temp> quit
~/home/temp> Command not found.
~/home/temp> quit | /cat/proc/testprogram
~/home/temp> Goodbye!
~/home/temp> ./testprogram &
Welcome to Testprogram. Enter command:
~/home/temp> ls /tmp # do whatever else you want to do on the shell
# ... later
~/home/temp> jobs # what was running?
[1]+ Running ./testprogram &
~/home/temp> fg # Brings testprogram to foreground, does not re-prompt
quit
Goodbye!
~/home/temp>