osx - Python 2 subprocess arguments error under Mac -


i'm trying mac version of program runs fine under windows, using python 2.7. under mac (os x el capitan running in virtualbox), fails because arguments pass shell not recognized properly.

original code:

for item in source_files:      # core process     output = sub.popen(["mhl", "verify", "-vv", "-f", item, ">", text_report],                        shell=true,                        stdout=sub.pipe,                        stderr=sub.pipe)     stdout_value, stderr_value = output.communicate() 

under mac 'mhl' argument recognized tried this:

sub.popen(['mhl verify -vv -f', item, '>', text_report] 

now command works item (a .mhl file) not recognized tried this:

sub.popen(['mhl verify -vv -f', '/users/simon/documents/documents.mhl', '>', text_report] 

and this:

sub.popen(['mhl verify -vv -f', r'/users/simon/documents/documents.mhl', '>', text_report] 

same results, tells me mhl file should follow '-f' argument. if add item directly first argument works fine:

sub.popen(['mhl verify -vv -f /users/simon/documents/documents.mhl', '>', text_report] 

what missing here?

you asking os run executable 'mhl verify -vv -f', , there no such executable. no shell splitting takes place on spaces there.

with shell=true you'd want pass in one string, not separate arguments:

sub.popen('mhl verify -vv -f {} > {}'.format(item, text_report),           shell=true, stdout=sub.pipe, stderr=sub.pipe) 

note there little point in directing stdout pipe here, since stdout output mhl command being redirected file.

if wanted capture output of mhl command directly in python, i'd not use shell intermediary here; run without shell=true , use subprocess.check_output() retrieve output:

output = sub.check_output(['mhl', 'verify', '-vv', '-f', item]) 

note program name , arguments must passed in ready-split separate strings.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -