Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to ignore stdin input inside a script

Tags:

linux

shell

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.

I have a smaple script,

sample.sh script

------
./myprogram &
exit 0
------

but when I run,

%sh sample.sh

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.

Please suggest how I can update sample.sh script to achieve this.

like image 354
pawan Avatar asked Oct 21 '25 01:10

pawan


1 Answers

You can connect the program's standard-input to /dev/null:

./myprogram < /dev/null &
like image 170
ruakh Avatar answered Oct 22 '25 16:10

ruakh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!