Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exactly what is `< /dev/null ` when read is done by null? [duplicate]

Tags:

unix

ffmpeg

'> /dev/null' is very common syntax and that's something that is not a new concept; but, I have came to this scripting and couldn't figure the logic behind '< /dev/null' especially with FFMpeg.

I wrote dozens of scripts that handles FFMpeg, and I found that in order for script itself to successfully call and execute FFMpeg on its own, adding '< /dev/null' at end of command line of ffmpeg. For example:

ffmpeg -i $INPUT -c:v copy -c:a copy output.mp4 < /dev/null

But if I didn't add that sytnax at end of the command, script couldn't "push" the execution over to FFMpeg. I understood the whole concept when it comes to "write" as > for all null, stdout, stdin, but... read by null ? scratching on head

So, what is < /dev/null exactly?

like image 287
Faron Avatar asked Dec 26 '15 17:12

Faron


1 Answers

For many systems, you can consult the manual page for special devices. For example, Linux null(4) documents:

Reads from /dev/null always return end of file

FreeBSD null(4) says it differently:

The null device accepts and reads data as any ordinary (and willing) file - but throws it away. The length of the null device is always zero.

which is less clear. Solaris null(7) says

Reads from a null special file always return 0 bytes.

You would see a redirect from /dev/null in a script when it is appeasing some program which wants to read from its standard input, but the script is not going to provide any data. If it were not redirected, the program might wait for keyboard input, for example.

like image 152
Thomas Dickey Avatar answered Oct 05 '22 02:10

Thomas Dickey