Federer
Federer

Reputation: 34715

Python invoking shell command with params loop

The following little script is supposed to run a shell command with a parameter every 10 minutes. It's ran correctly once (30 minutes ago) however isn't playing ball now (should have done the process another 2 times since). Have I made an error?

while(True):
  subprocess.call(["command","param"])
  time.sleep(600)

Upvotes: 0

Views: 495

Answers (2)

Cryptite
Cryptite

Reputation: 1466

Try subprocess.Popen if you don't need to wait for the command to complete.

From the docs,

subprocess.call: Run the command described by args. Wait for command to complete, then return the returncode attribute.

Upvotes: 1

jdi
jdi

Reputation: 92559

You subprocess.call probably blocked on whatever your command was. I doubt its your python script, but rather whatever the shell command might be (taking too long).

You can tell if your command is completing or not by checking the return code:

print subprocess.call(["command","param"])

It should print 0 if it was successful, or raise an exception if the command has problems. But if you never see consecutive prints, then its never returning from the call.

Upvotes: 2

Related Questions