Reputation: 120
I am trying to store the out put of mediainfo command in linux in a variable. I am using the subprocess module for this. The problem is that the arguments for mediainfo command have special characters. here is the snippet
the shell command is:
mediainfo --Inform="Video;%DisplayAspectRatio%" test.mp4
and the python code is:
mediain = str('--Inform="Video;%DisplayAspectRatio%"')
mediaout = subprocess.check_output("medainfo", mediain ,"test.mp4")
print mediaout
error im getting is
--Inform="Video;%DisplayAspectRatio%"
Traceback (most recent call last):
File "./test.py", line 8, in <module>
mediaout = subprocess.check_output("medainfo", '--Inform="Video;%DisplayAspectRatio%"',"test.mp4")
File "/usr/lib64/python2.7/subprocess.py", line 568, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 660, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
any help in this regardd is aprreciated, absolute newbie in python Thanks
Upvotes: 3
Views: 2402
Reputation: 10951
Possibly better to keep the command format in a string and pass it to subprocess.check_out()
as list:
cmd = 'mediainfo --Inform=Video;%DisplayAspectRatio% test.mp4'
mediaout = subprocess.check_out(cmd.split()) #will split cmd over whitespaces and pass to check_out as a list.
print mediaout
Upvotes: 0
Reputation: 149893
subprocess.check_output()
expects the first argument to be a list. Try this:
args = ['mediainfo', '--Inform=Video;%DisplayAspectRatio%', 'test.mp4']
mediaout = subprocess.check_output(args)
print mediaout
Upvotes: 1