How to use linux command in subprocess python -


i have linux command below:

 find /data/*/hr/ -printf "%f: %p: %u: %g %m (%m) \n" 

how use in python subprocess check_output

i have tried below not working

 file_name = "/data/*/%s/" % (filename)  get_perm = check_output(["find", file_name, "-printf", '\"%f: %p: %u: %g %m (%m) \n\"']) 

error getting:

find: ‘/data/*/hr/’: no such file or directory traceback (most recent call last):   file "handover.py", line 90, in <module>     get_perm = check_output(["find", file_name, "-printf", '\"%f: %p: %u: %g %m (%m) \n\"'])   file "/usr/lib64/python2.7/subprocess.py", line 573, in check_output     raise calledprocesserror(retcode, cmd, output=output) subprocess.calledprocesserror: command '['find', '/data/*/hr/', '-printf', '"%f: %p: %u: %g %m (%m) \n"']' returned non-zero exit status 1 

finally,

i found below method

cmd = "find /data/*/{}/* -printf \"%f:%p:%u:%g:%m\n\"".format(filename) info = subprocess.popen(cmd,stdout=subprocess.pipe,shell=true) print info.stdout.read() 

this solves problem


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -