小编Mar*_*aje的帖子

subprocess.run 输出为空(python 3.8)

我正在尝试使用以下代码捕获命令的输出:

lines = subprocess.run(['ffmpeg', '-hide_banner', '-nostats', '-i', in_filename, '-vn', '-af', 'silencedetect=n={}:d={}'.format(silence_threshold, silence_duration), '-f', 'null', '-'], capture_output=True, text=True, shell=True, check=True, encoding='utf-8').stdout 
print (lines)
Run Code Online (Sandbox Code Playgroud)

但lines是一个空字符串并且没有打印任何内容。删除后capture_output=True,将显示正确的输出(不打印)。

我测试了许多组合,包括删除所有subprocess.run参数并仅包含capture_output=True相同的结果。

我还用很少的参数进行了测试,举了一个最小的例子:subprocess.run(['ffmpeg', '-version'], capture_output=True, text=True, shell=True, check=True, encoding='utf-8').stdout

还进行了测试stdout=subprocess.PIPEstderr=subprocess.PIPE作为subprocess.run参数而不是capture_output=True

我不明白发生了什么事。提前致谢!

python subprocess ffmpeg

6
推荐指数
1
解决办法
1843
查看次数

标签 统计

ffmpeg ×1

python ×1

subprocess ×1