Start job from python, redirect output to file -
i have script, update_file
, typically run so:
sudo update_file (file) > ./logs/(file) &
i wondering proper syntax/is possible, call script within python script , still have redirect output update_file
file , have created system job.
edit: should note, run against multiple (file)
s pass variable.
first, subprocess
module how execute programs python. section replacing older functions subprocess
module in documentation shows how transform typical shell functionality python.
because you're using &
background task, you'll want create popen
, , job-handling later. so:
jobs = [] # ... each time want run on file ... jobs.append(subprocess.popen(['sudo', 'update_file', file], stdout=open(os.path.join('logs', file), 'w')) # ... @ exit time ... job in jobs: job.wait() job.stdout.close()
Comments
Post a Comment