Date: Wed, 10 Jun 2015 15:42:26 -0400 From: Robert Simmons <rsimmons0@gmail.com> To: freebsd-python@freebsd.org Subject: Python Subprocess Crontab Problem Message-ID: <CA%2BQLa9BjC=M-5wxA0gzoTJO1xHL9XbhpTN10QhhrdCG9bxf3Lg@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2BQLa9BjC=M-5wxA0gzoTJO1xHL9XbhpTN10QhhrdCG9bxf3Lg>