我试图使用以下代码捕获命令的输出:
但是lines是个空字符串,输出为空。 当删除
我尝试了许多组合,包括删除所有
我还使用了少量参数进行最小示例测试:
我无法弄清楚到底发生了什么。提前感谢!
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)
但是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.PIPE
和stderr=subprocess.PIPE
作为subprocess.run
参数,而不是capture_output=True
.我无法弄清楚到底发生了什么。提前感谢!
subprocess
中的check_output()
和subprocess.Popen().communicate()
?请参考这个答案。 - thuyein