From owner-freebsd-python@FreeBSD.ORG Wed Jun 10 19:42:26 2015 Return-Path: Delivered-To: freebsd-python@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D9ECC52F for ; Wed, 10 Jun 2015 19:42:26 +0000 (UTC) (envelope-from rsimmons0@gmail.com) Received: from mail-ig0-x230.google.com (mail-ig0-x230.google.com [IPv6:2607:f8b0:4001:c05::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A71951BC7 for ; Wed, 10 Jun 2015 19:42:26 +0000 (UTC) (envelope-from rsimmons0@gmail.com) Received: by igbzc4 with SMTP id zc4so43369429igb.0 for ; Wed, 10 Jun 2015 12:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=GOgLvGlUWh7l+icGSaxf4mLnwbDmYgW0+jPVRmZId9g=; b=qR8RMnZqHG19Cw53tSIVqcbFzweHrLSGtS4Jfqdw3nf5hGKXTGQXWzCr0qSMKUnAIz OZCfdBDrtuB2t1WcFjpofVeTqwEmGZfpZTESIiEbXC5latBvU/FofE8KAwj8MoMXaa4P aLMs1+vMg9Iah7oUP9roQarKA9+V02PavMrdafbllCURVu+1Mf73pxp3qPejcr5hWTLU wa/yDlJ0B2XQbtllTWWxlGo+znIg4/q2uLXz4jO3pN8xMqKrT2VSPF4aktvoLDAQ6ooj AkuU72J5WVbxM7SCMz5d/br0om4zSboBwyaeypgq545uhXBNcbwlVfnJDJRzTQGwNjjF 5mfw== MIME-Version: 1.0 X-Received: by 10.43.178.195 with SMTP id ox3mr755156icc.10.1433965346057; Wed, 10 Jun 2015 12:42:26 -0700 (PDT) Received: by 10.64.60.73 with HTTP; Wed, 10 Jun 2015 12:42:26 -0700 (PDT) Date: Wed, 10 Jun 2015 15:42:26 -0400 Message-ID: Subject: Python Subprocess Crontab Problem From: Robert Simmons To: freebsd-python@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jun 2015 19:42:26 -0000 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)