Python subprocess.check_output -


i trying use couple shell level commands python , set variables later use in program not appear calling commands outputs should simple 1-liners. not quite sure if it's due % or ; signs.

current_vcodec = subprocess.check_output(["mediainfo", "--inform='video;%codecid%'", "%s" % source]) current_acodec = subprocess.check_output(["mediainfo", "--inform='audio;%codecid%'", "%s" % source]) duration = subprocess.check_output(["mediainfo", "--inform='video;%duration%'", "%s" % source]) 

i highly recommend use kenneth reitz's envoy python wrapper subprocess. makes calls command line far easier use.

import envoy res = envoy.run("mediainfo --inform='video;%codecid%' {0}".format(source)) if res.status_code != 0:    print("media info failure: {0}".format(res.std_out + " " + res.std_err))  else:    print(res.std_out)    current_vcodec = res.std_out 

if needed, can "escape" % backslash, i'm not sure that's problem. ; shouldn't problem.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -