0

I try to write some Data in a CSV file by a Python3 script. If I run this direct in the CMD it works very well, but if i run it by cron ( setted up by crontab -e) it does not work.

Now I've found out that I need the direct path (hardcoded in my code as a constant string) to this file.

But my first approach was confusing me. I run the command Path(os.getcwd()).joinpath('Data/test.csv') and get the correct path /home/pi/Documents/Project/Data/test.csv. But as i run it by a cron, the path was /home/pi/Data/test.csv.

The project is located at /home/pi/Documents/Project/. Why Path(os.getcwd()).joinpath('Data/test.csv') returns an other path, than a direct call by cmd?

What could i change that i've the same behavior in a cron and in a comandline call of my scirpt?

EDIT

This is my crontab entry:
00 9,15 * * * python3 /home/pi/Documents/Projects/temperatureCheck/temperatureCheck.py

1
  • Your command line runs in /home/pi/Documents/Project. Cron runs in your home directory. How would crontab know which current directory you might change to in your terminal session? Apr 27 '20 at 14:12
0

Prefix your crontab command with:

cd /home/pi/Documents/Project && ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.