问题描述
我有一个程序"myprogram",它在控制台上运行时等待回车键.当我们按某个键后,它退出.我想在后台运行此myprogram并忽略stdin输入.
I have a program "myprogram" and it waits for a enter key when run on console. After we press somekey it exits. I want to run this myprogram in background and ignore stdin input.
我有一个脚本,
sample.sh脚本
sample.sh script
------
./myprogram &
exit 0
------
但是当我跑步时,
%sh sample.sh
%sh sample.sh
我的程序如何从stdin中获取一些输入并退出..我想阻止它从stdin中获取任何输入,因此即使在sample.sh退出后,myprogram仍可以继续运行.
some how myprogram gets some inputs from stdin and exits.. I want to stop it from getting any input from stdin so even after sample.sh exits myprogram continue to run.
请建议我如何更新sample.sh脚本以实现此目的.
Please suggest how I can update sample.sh script to achieve this.
推荐答案
您可以将程序的标准输入连接到/dev/null
:
You can connect the program's standard-input to /dev/null
:
./myprogram < /dev/null &
这篇关于如何忽略脚本中的标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!