State script on startup


#1

Hello all

I have a script to init the can bus for IoT card.
This script is stored to /home/root on my board.

What is the best way to run on startup ?
Can I do that from my app?

Thanks.


#2

I am using popen, WIFEXITED to execute my shell script from my App. below is the sample code for your reference but i don’t know whether it is best practice or not. If someone know better way please share with us

char line[256];
FILE* fp = popen("your.sh 2>&1", "r");  //2>&1 redirect stderr to stdout//
LE_ASSERT(fp != NULL);

    
while (fgets(line, sizeof(line), fp) != NULL)
{
    LE_INFO("your.sh output: %s", line);
}

int result = pclose(fp);
LE_FATAL_IF(!WIFEXITED(result), "Could not run your.sh");
const int exitCode = WEXITSTATUS(result);
LE_FATAL_IF(exitCode != 0, "your.sh failed with exit code %d", exitCode);

Thanks


#3

Thank work fine.
I have added the script in the .adef file too (with bundel …)