The following code illustrates how to launch a script programmatically (using the command interpreter):
#include <vxWorks.h> #include <stdio.h> #include <ioLib.h> #include <string.h> #include <errnoLib.h> #include <sysLib.h> #include <shellLib.h> #include <taskLib.h> STATUS runScript ( char * scriptPath /* full path to script to execute */ ) { char * shellTaskName; int fdScript; STATUS retVal = ERROR; if ((fdScript = open (scriptPath, O_RDONLY, 0)) == ERROR) { printErr ("Error opening script at '%s' [%s]!\n", scriptPath, strerror (errnoGet ())); return retVal; } /* Launch a new session to execute the script */ retVal = shellGenericInit ("INTERPRETER=Cmd", 0, NULL, &shellTaskName, FALSE, FALSE, fdScript, STD_OUT, STD_ERR); /* Wait for the script execution to end by monitoring the shell task life */ do taskDelay (sysClkRateGet ()); while (taskNameToId (shellTaskName) != TASK_ID_ERROR); close (fdScript); return retVal; }