Creating Linux in Job (Scheduling) in Python

I am trying to schedule a series of jobs in linux using a python script. My script currently looks something like this:

import subprocess
command = 'python foo.py %s %s | at %s' % (arg1, arg2, starttime) 
subprocess.Popen([command,], shell=True)

But this does not work, and I was hoping that someone could advise what I should do.

+3
source share
2 answers

What is your problem in using the command at, it should get a string so you want more

command = 'echo python foo.py %s %s | at %s' % (arg1, arg2, starttime)

or in a more pythonic way

sched_cmd = ['at', starttime]
command = 'python foo.py %s %s' % (arg1, arg2)
p = subprocess.Popen(sched_cmd, stdin=subprocess.PIPE)
p.communicate(command)
+2
source

If you go in shell=True, Popen()expect a line:

import subprocess
command = 'python foo.py %s %s | at %s' % (arg1, arg2, starttime) 
subprocess.Popen(command, shell=True)

Also, what do you mean by "not working"? This works fine for me:

>>> import subprocess
>>> subprocess.Popen('echo "asd" | rev', shell=True).communicate()
dsa
(None, None)

And your code also:

>>> import subprocess
>>> subprocess.Popen(['echo "asd" | rev',], shell=True).communicate()
dsa
(None, None)
+3
source

All Articles