muella91
Posts: 4
Joined: Sat Dec 01, 2018 7:00 am

Autostart of executable

Sun Jan 13, 2019 8:13 am

Hello,

I want to execute a compiled C++ programm, so an executable always when the Pi powers up.
Basically, my programm does not need a terminal, but I want to open and cout some stuff for error printing.
For testing I just wrote this two files:

Code: Select all

#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
	while (1) {
		cout << "Hello World!" << endl;
		sleep(1);
	}
	
}

Code: Select all

#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
	execl("/usr/bin/lxterminal", "-l", "-e", "./test", NULL);
}

If I test them by myself, they work.
First I tried an script in the init.d folder, including changing R/W settings, setting as default and so on. It did not work, why I thought its maybe a problem with the runlevel. I tried to work with the rc.local file, also did not start when I powered up the Pi.
So after some tries, I decided to give Cron a chance. I checked if Cron runs well with:
(by the way, I know it start every minute, not only when powering up)

Code: Select all

* * * * * echo "hello" >> /home/pi/Desktop/myCron.txt
Works.

Now I tried the following:

Code: Select all

* * * * * /usr/local/bin/execTest
It does not work. Of course the "test" executable is in the same folder. I also tired diffrent directorys, did not help.

Thanks for any advice!

wh7qq
Posts: 1243
Joined: Thu Oct 09, 2014 2:50 am

Re: Autostart of executable

Sun Jan 13, 2019 4:56 pm

Code: Select all

@reboot
is a cron command to perform the following command(s) once at boot up. See:

https://www.maketecheasier.com/beginner ... ron-linux/

User avatar
thagrol
Posts: 1471
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Autostart of executable

Sun Jan 13, 2019 5:21 pm

Output from programs started by cron gets thrown away unless explictly redirected somewhere.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

muella91
Posts: 4
Joined: Sat Dec 01, 2018 7:00 am

Re: Autostart of executable

Mon Jan 14, 2019 3:58 pm

thagrol wrote:
Sun Jan 13, 2019 5:21 pm
Output from programs started by cron gets thrown away unless explictly redirected somewhere.
Yes, just checked, my programm runs with @reboot. Cron just does not open the terminal. So how do I solve this?

Thank you!

Return to “Troubleshooting”