5

I am automatically running a simple python program from start up using cron. The pi boots / automatically logs in, displays the command line and runs the python program but the print output (updating count) is not displayed.

The print output works fine if I run the program via idle (ie having enabled LXDE) and it also works fine if (without running the LXDE desktop) I manually run the program from the command line, e.g. sudo python pimon.py

What is needed to see the print output when I start the program using cron? I do not want to have to enable the LXDE desktop first.

The crontab entry is: @reboot python /home/pi/Python27/pimon.py

Ghanima
16k17 gold badges66 silver badges127 bronze badges
asked Apr 2, 2015 at 17:21
4
  • Please show your crontab entry. Commented Apr 2, 2015 at 17:26
  • 3
    Your script run by cron simply has no console to print its output too. The behaviour you describe is perfectly normal. Best way to work around: make your script output to a file. Commented Apr 2, 2015 at 17:29
  • 1
    Where have you told the output to go? A cron job is not started from a terminal so is not attached to a keyboard or screen. Perhaps you need to redirect the output to a file. Commented Apr 2, 2015 at 17:29
  • See also: raspberrypi.stackexchange.com/questions/40493/… Commented Jan 6, 2016 at 0:25

1 Answer 1

4

As others have noted in the comments, you need to redirect the output from the command somewhere.

This will write to a file, overwriting the file if it already exists.

@reboot python /home/pi/Python27/pimon.py > /path/to/output_file.txt

Change> to>> if you want to append to an existing file.

Check this link for more information on standard input and output redirection.

Ghanima
16k17 gold badges66 silver badges127 bronze badges
answered Apr 3, 2015 at 17:18
1
  • Please note that the ampersand is not necessary since cron already forks the program. Commented Apr 3, 2015 at 19:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.