目前我的代码是
print ("Getting MediaInfo...")
mediainfo_command = ("mediainfo", input_file_full)
mediainfo = (subprocess.call(mediainfo_command))
所以我想要做的是将subprocess.call的输出保存到变量mediainfo中。但我不想在终端显示命令的实际输出。
这可能吗?
答案 0 :(得分:1)
请改用subprocess.Popen.communicate。
print ("Getting MediaInfo...")
mediainfo_command = ["mediainfo", input_file_full]
proc = subprocess.Popen(mediainfo_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
mediainfo, mediaerr = proc.communicate()
答案 1 :(得分:0)
您可能还想查看subprocess.check_output
。
print ("Getting MediaInfo...")
mediainfo_command = ["mediainfo", input_file_full]
mediainfo = subprocess.check_output(mediainfo_command)