Python Subprocess Crontab Problem
Robert Simmons
rsimmons0 at gmail.com
Wed Jun 10 19:42:26 UTC 2015
I'm running into a wall with regards to using subprocess.call in a
python script running in a crontab. I have isolated this problem to be
subprocess not able to find the 7z executable. I have tried adding
PYTHONPATH=$PATH to crontab, I have tried adding shell=True to
subprocess.call, and I have tried using /usr/loca/bin/7z rather than
7z. None of these have fixed the problem. The error that I get is the
following:
/usr/local/bin/7z: realpath: not found
/usr/local/bin/7z: dirname: not found
exec: /../libexec/p7zip/7z: not found
Here is how I'm calling the script in crontab:
PATH=$PATH:/usr/local/bin
@every_minute $HOME/test.py >> $HOME/test.error 2>&1
Here is the contents of my script (test.py):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import subprocess
import tempfile
thing = 'blahblahblah'
errors = open('/home/myuser/error', 'wb')
with tempfile.TemporaryDirectory() as tmpdirname:
tempthing = os.path.join(tmpdirname, thing)
fh = open(tempthing, 'wb')
fh.write(b'123')
fh.close()
zipname = '{}.zip'.format(thing)
ziptempfile = os.path.join(tmpdirname, zipname)
zipper = subprocess.call(['7z', 'a', '-p{}'.format('something'),
'-tzip', '-y', ziptempfile, tempthing], stdout=errors,
stderr=subprocess.STDOUT)
More information about the freebsd-python
mailing list