Python Forum
How to run unix command in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run unix command in python
#1
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?
Reply
#2
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to run unix command using spur purnima1 11 7,062 Sep-07-2018, 07:57 AM
Last Post: purnima1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020