Python Forum

Full Version: How to run unix command in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I am new to python and have a query in python as, how to run unix find command and need the output in a list.

I want to run this unix command and need an output in a list. is it possible?

 find /user/s/balaji/ -mtime +20 -type f | grep -v .ksh | grep -v .txt 
will you please help me how to do this in python?
subprocess.check_output

command = "find /user/s/balaji/ -mtime +20 -type f | grep -v .ksh | grep -v .txt".split()

output = subprocess.check_output(command).decode('utf-8')

ouptut_list = output.split('\n') # every output line will be a list element