[Python] Python Subprocess returns non-zero exit status only in cron

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I have a Python script that manages a series of CasperJS tasks and processes the result. It runs well from the command line, but when I run the script in cron, I get the error:

    CalledProcessError: Command '['/path/to/casperjs', '/path/to/doSomething.js', 'args']' returned non-zero exit status 1


    In Python, I call CasperJS:

    response = subprocess.check_output(['/path/to/casperjs', '/path/to/doSomething.js', 'args'], shell=True)


    I have tried shell=False and Popen as well, but I get the same result. I also tried making the entire command a string (instead of list), but that didn't help either.

    Running '/path/to/casperjs /path/to/doSomething.js args' returns exit code 0 when run in the shell.

    I have also added PATH=/usr/bin:/bin:/sbin:/usr/local/bin to my crontab to no avail. (As suggested in this question.)

    Any ideas why I'm only getting this error in cron? Thanks!!

    EDIT: In accordance with the answer below, setting shell=False and stderr=subprocess.STDOUT made everything work...

    Continue reading...

Compartilhe esta Página