Redirecting to stdin in order to execute script in

2019-05-23 23:39发布

问题:

I need to execute a script in vxWorks 6.7. It can be done with the execute() function in vxworks 5.5. The solution that I am applying is to use stdin redirection as in the following code:

    newStdIn = open("myScript.txt",O_RDONLY,0644);
    oldStdIn=ioGlobalStdGet(STD_IN);
    ioGlobalStdSet(STD_IN, newStdIn);
    /*Read file here and execute*/
    ioGlobalStdSet(STD_IN,oldStdIn); /*Restore old stdIn*/
    close(newStdIn);

I am missing the read and execute part (where the comment is).

EDIT: According to the vxworks kernel programmers guide, the way to execute a script is as follows:

    fdScript = open ("myScript", O_RDONLY);
    shellGenericInit ("INTERPRETER=Cmd", 0, NULL, &shellTaskName, FALSE, FALSE, fdScript, STD_OUT, STD_ERR);
    do
       taskDelay (sysClkRateGet ());
    while (taskNameToId (shellTaskName) != ERROR);
    close (fdScript);

But it will open a new shell without processing the script. The problem with this is that my application won't do anything after calling shellGenericInit.

回答1:

It looks like you are starting a Cmd shell, rather than a C Interpreter shell. Since you mention that you used the execute() function in 5.5, I assume that your script is for the C Interpreter.

Try changing "INTERPRETER=Cmd" to "INTERPRETER=C".



标签: vxworks