【发布时间】:2011-07-19 10:04:30
【问题描述】:
如果我有一个命令行程序作为与命令行交互的后台线程(AKA 与 ./program &)执行,我如何向它发送命令?有没有办法(例如,使用“管道”)发送字符,就好像它们是在命令行上输入的一样?
简化的命令行示例:
没有&(正常情况):
~/home/temp> ./testprogram
~/home/temp> Welcome to Testprogram. Enter command:
~/home/temp> Welcome to Testprogram. Enter command: quit
~/home/temp> Goodbye!
使用 &(我的情况!):
~/home/temp> ./testprogram &
~/home/temp> Welcome to Testprogram. Enter command:
~/home/temp> quit
~/home/temp> Command not found.
A ps -e | grep testprogram 显示它仍在运行,但现在永远无法在“kill”命令之外终止。
理想的情况如下:
~/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!
我该怎么做?
【问题讨论】:
标签: linux command-line send