如何忽略脚本中的标准输入 [英] how to ignore stdin input inside a script

查看:74
本文介绍了如何忽略脚本中的标准输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序"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 &

这篇关于如何忽略脚本中的标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆