12

I have a misbehaving program that I need to call from my script. It exits as soon as it sees something on stdin. Is there a way to close stdin?

21

Is there a way to close stdin?

Closing File Descriptors

  • n<&- Close input file descriptor n.

  • 0<&- or <&- Close stdin.

Source Chapter 20. I/O Redirection

8

Just pipe in a program with no output:

: | misbehaving_program
  • Wow, what is this? What does ':' do? – KaiserKatze May 24 at 5:47
  • ":" is an internal command of the shell that does nothing. It lets you introduce comments, or can be used for redirections. For example ": > file" creates an empty file. Or ": |" in this case feeds an empty stream to the command. – Raúl Salinas-Monteagudo May 24 at 7:16
8

Found it, you can close stdin with:

exec 0<&-
5

According to what you say, you might fix your problem by simply

pickyProgram < /dev/null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.