سؤال

At the moment the code I have is

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

So what I want to do is save the output of the subprocess.call into the variable mediainfo. But I don't want to display the actual output of the command in the terminal.

Is this possible?

هل كانت مفيدة؟

المحلول 2

You may also want to look at subprocess.check_output.

print ("Getting MediaInfo...")
mediainfo_command = ["mediainfo", input_file_full]
mediainfo = subprocess.check_output(mediainfo_command)

نصائح أخرى

Use subprocess.Popen.communicate instead.

print ("Getting MediaInfo...")
mediainfo_command = ["mediainfo", input_file_full]
proc = subprocess.Popen(mediainfo_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
mediainfo, mediaerr = proc.communicate()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top