相关疑难解决方法(0)

Bash:在读取循环中读取输入不起作用

在 while 读取循环中读取输入似乎不起作用

while read line
do
 echo "get some input from the user"
 read response
done < some_file.txt
Run Code Online (Sandbox Code Playgroud)

执行不会像读取在循环之外那样暂停。为什么是这样?是否有在 while 读取循环中读取输入的解决方法?

bash

14
推荐指数
2
解决办法
2万
查看次数

为什么 FFmpeg 在 while 循环中需要 nostdin?

如果我有:

for i in *.mov;
do
ffmpeg -y -i $i -c:v copy -c:a copy ${i%%.mov}.mp4
done
Run Code Online (Sandbox Code Playgroud)

这运行良好。但如果我跑:

find . -name "*.ts" -print0 | while read -d $'\0' file;
do
  ffmpeg -i "$file" -c copy -map 0 "${file%%.ts}_rec.mp4";
done
Run Code Online (Sandbox Code Playgroud)

这失败了。我需要输入-nostdin。

find . -name "*.ts" -print0 | while read -d $'\0' file;
do
  ffmpeg -nostdin -i "$file" -c copy -map 0 "${file%%.ts}_rec.mp4";
done
Run Code Online (Sandbox Code Playgroud)

文档解释说,这会禁用标准输入上的交互,并且对后台进程很有帮助。

为什么在第二种情况下 FFmpeg 是后台进程?或者还有其他问题吗?

bash ffmpeg

2
推荐指数
1
解决办法
3428
查看次数

标签 统计

bash ×2

ffmpeg ×1