yamin volazi
yamin volazi

Reputation: 11

execute linux shell command from python script

I have a python script that contains a Linux shell command. I'm using subprocess.check_output. My question is about the faster python method to execute a Linux shell command from python script like os.system().

Upvotes: 1

Views: 119

Answers (2)

Roman Zhidkov
Roman Zhidkov

Reputation: 1

The better way:

from subprocess import call
call('ls')

Please check: https://docs.python.org/2/library/subprocess.html

Upvotes: 0

Stéphane
Stéphane

Reputation: 1354

  • I like subprocess.Popen, but it has troubles (maybe it can't) to deal with '>' ==> unconvenient if you have a '>' in the command line
  • otherwise subprocess.check_output

Upvotes: 0

Related Questions