Page 1 of 1
No Program Output Window when running from Cron.
Posted: Sun May 14, 2017 2:51 pm
by RDS
I have a Pi set up to take pictures at certain times of the day and save them to a folder on the Micro SD card, using Cron. This works very well and appears to be very reliable.
I notice though that if I run the same program manually, it produces an output window which contains the text that I have entered in to the program, namely 'Picture taken and sent to file'. However, when Cron runs the program, even though it correctly saves the picture, it does not produce the output window.
I would now like to use Cron on another one of my Pi's for another purpose but this time it is essential that the output window is visible.
Is there something extra that I need to enter into the program when running from Cron to ensure it produces the output window, that incidentally is headed, 'Python 3.4.2 shell'?
Re: No Program Output Window when running from Cron.
Posted: Sun May 14, 2017 3:00 pm
by Martin Frezman
Running things "in the background" and "out of sight" is kinda the main point of cron. It can be bent into doing what you want, but you might consider other approaches. Let me repeat that in case fast readers miss it on the first pass: It can be done, but it is not the usual approach, and if you really need this sort of display, you ought to consider running your program another way (say, via the startup files that people use to launch things "in the GUI"). The names and syntax of these files escapes me at the moment, but I am sure others will be along to fill in the details.
Usually, when a program is running "in the background" and "out of sight", output that would normally be displayed for a user to see is, instead, directed into log files. The maintainer is expected to read and analyze these log files to figure out if the program is working correctly.
Re: No Program Output Window when running from Cron.
Posted: Sun May 14, 2017 3:11 pm
by pcmanbob
Hi.
Gorden77 explains how to do it in the thread.
viewtopic.php?f=32&t=183624
Re: No Program Output Window when running from Cron.
Posted: Sun May 14, 2017 3:49 pm
by RDS
@Martin Fezman
Thank you for the assurance it can be done.
@pcmanbob
Thank you for the link, I will give that a try later.
Just one other thing though: When using Cron, I know how to go back into Cron to edit the settings. When using this method what is the equivalent, or is it just a matter of deleting the file (/usr/bin/python /home/pi/filename.py) that has been created.
Re: No Program Output Window when running from Cron.
Posted: Sun May 14, 2017 3:50 pm
by Martin Frezman
Well, except for the silly UUOS (Useless Use of Sudo).
Re: No Program Output Window when running from Cron.
Posted: Mon May 15, 2017 12:20 am
by scruss
Or another way to do it:
- in your cron job — redirect your program output to a file, like so: … crontab fields … python3 /home/pi/filename.py > /home/pi/output.txt
- In your ~/.config/lxsession/LXDE-pi/autostart file, add the line: @lxterminal -t 'Python 3.4.2 shell' -e 'tail -f /home/pi/output.txt'
Your program can quite happily restart and overwrite output.txt, but what it
mustn't do is delete it. If that happens, the tail command will exit, leaving you with a useless window. Despite the window title, it's not really a shell, it's just watching the output file for changes.
There is no need to use sudo here at all.
Re: No Program Output Window when running from Cron.
Posted: Sat May 27, 2017 9:27 pm
by RDS
scruss wrote:Or another way to do it:
- in your cron job — redirect your program output to a file, like so: … crontab fields … python3 /home/pi/filename.py > /home/pi/output.txt
- In your ~/.config/lxsession/LXDE-pi/autostart file, add the line: @lxterminal -t 'Python 3.4.2 shell' -e 'tail -f /home/pi/output.txt'
Sorry for the delay in responding and I am OK with the first part but for item number 2 above, could you please explain where this would be added.
Re: No Program Output Window when running from Cron.
Posted: Sat May 27, 2017 9:48 pm
by scruss
at the end of the file
Re: No Program Output Window when running from Cron.
Posted: Fri Jun 02, 2017 6:32 pm
by RDS
@scruss
Thanks but sorry I meant where would that file be placed. I am not familiar with a :
~/.config/lxsession/LXDE-pi/autostart file
Re: No Program Output Window when running from Cron.
Posted: Fri Jun 02, 2017 7:17 pm
by Paeryn
RDS wrote:@scruss
Thanks but sorry I meant where would that file be placed. I am not familiar with a :
~/.config/lxsession/LXDE-pi/autostart file
~ is your home directory, for the user
pi it expands to
/home/pi so that is equivalent to
/home/pi/.config/lxsession/LXDE-pi/autostart
Typically the shell will expand it for you so you can type it as scruss gave it, e.g.
Code: Select all
nano ~/.config/lxsession/LXDE-pi/autostart
Re: No Program Output Window when running from Cron.
Posted: Fri Jun 02, 2017 10:06 pm
by RDS
@Paeryn
Thank you