pawan
pawan

Reputation: 141

how to ignore stdin input inside a script

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.

Upvotes: 4

Views: 2698

Answers (1)

ruakh
ruakh

Reputation: 183554

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

./myprogram < /dev/null &

Upvotes: 5

Related Questions