2013-10-03 72 views
0

目前我的代碼是如何抑制subprocess.call中的輸出,但保存輸出?

print ("Getting MediaInfo...") 
mediainfo_command = ("mediainfo", input_file_full) 
mediainfo = (subprocess.call(mediainfo_command)) 

所以我想要做的是subprocess.call的輸出保存到變量的MediaInfo。但我不想在終端中顯示該命令的實際輸出。

這可能嗎?

回答

0

您可能還想看看subprocess.check_output

print ("Getting MediaInfo...") 
mediainfo_command = ["mediainfo", input_file_full] 
mediainfo = subprocess.check_output(mediainfo_command) 
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()