gpt4 book ai didi

unix - 当读取由 null 完成时, `
转载 作者:行者123 更新时间:2023-12-05 01:21:51 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





What is </dev/null in bash?

(4 个回答)


6年前关闭。



'> /dev/null'是非常常见的语法,这不是一个新概念;但是,我来到了这个脚本,无法弄清楚 '< /dev/null' 背后的逻辑尤其是 FFMpeg。

我写了几十个处理FFMpeg的脚本,我发现为了让脚本本身成功调用和执行FFMpeg,添加'< /dev/null ' 在 ffmpeg 的命令行末尾。例如:

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

但是,如果我没有在命令末尾添加该 sytnax,则脚本无法将执行“推送”到 FFMpeg。当谈到“写”时,我将整个概念理解为 >对于所有 null、stdout、stdin,但是... read由空?抓挠头

那么, < /dev/null 是什么?确切地?

最佳答案

对于许多系统,您可以查阅特殊设备的手册页。例如,Linux null(4)文件:

Reads from /dev/null always return end of file



FreeBSD null(4)说的不同:

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.



这不太清楚。索拉里斯 null(7)

Reads from a null special file always return 0 bytes.



您会看到来自 /dev/null 的重定向在脚本中,当它正在安抚一些想要从其标准输入中读取的程序时,但该脚本不会提供任何数据。例如,如果它没有被重定向,程序可能会等待键盘输入。

关于unix - 当读取由 null 完成时, `</dev/null ` 到底是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34473563/

24 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com