Harsh
Harsh

Reputation: 45

How to execute a shell command in Python 2.7?

Written both shell and oython codes for understanding

Please help to achieve output of shell in python

Upvotes: 1

Views: 5083

Answers (1)

Trevor Merrifield
Trevor Merrifield

Reputation: 4691

You can hook up stdin and stdout of processes together in python using Popen but it's usually easiest to let shell shell do the work, for example you can:

subprocess.check_output('ls | grep something', shell=True)

Related: How do I use subprocess.Popen to connect multiple processes by pipes?

Upvotes: 2

Related Questions