Executing a script from inside code in VxWorks 6.7

扶醉桌前 提交于 2019-12-31 04:03:28

问题


In VxWorks 5.5.1 you could run a script using the execute command. In VxWorks 6.7 the execute command is no longer supported. Does anyone now if there is a replacement? I am specifically talking about from inside code not command line.


回答1:


Through much research it appears like there are a few ways to accomplish this but none is exactly the same as the execute command from before. As I stated in the comment below it turns out that the execute command is not an official API call.

1) shellCmdExec can be used but most be called from inside the shell task. 2) The solution we choose to employ - which is to call it from within our startup script

3) And a hack way:

fd = open("/y/startup.go", 0, 0) /* open the script you want to execute / v=shellFromNameGet("tShell0") / Get the shell i.d. */

/* Use shellinOutGet to save off the standard in of the shell / shellInOutSet (v, fd, -1, -1) / Set the standard in of the shell to the file */

/* Here you should restore the standard in (do a shellInOutGet beforehand). Do it after the shell is done with the script. I would say that your script should increrment a variable when ti is done. */

close(fd)




回答2:


There's a solution in the VxWorks Kernel programmer's guide 6.7, the problem is that it did not work for me, but it could help you:

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

Check Section 15.2.15 of the document.




回答3:


You can do it in the serial driver layer. Try the following code. It shows how to send text to the shell's input.

For example,

pass_to_sio("memShow; ifconfig"); in your c code.

-> sp pass_to_sio, "memShow; ifconfig" in the shell.

pass_to_sio("< test.scr"); in your c code if you want to run a script file.

-> sp pass_to_sio, "< test.scr" in the shell if you want to run a script file.

void pass_to_sio(char *input)
{
    int old_priority;

    taskPriorityGet(taskIdSelf(),&old_priority);

    taskPrioritySet(taskIdSelf(),250); /* task priority must be lower than tShell0 */

    NS16550_CHAN *pChan = &ns16550Chan[0]; /* this line depends on your BSP */

    while (input != NULL && *input != NULL)
    {
        (*pChan->putRcvChar) (pChan->putRcvArg, *input);
        input++;
    }

    (*pChan->putRcvChar) (pChan->putRcvArg, '\r');

    taskPrioritySet(taskIdSelf(),old_priority); 
}


来源:https://stackoverflow.com/questions/2909979/executing-a-script-from-inside-code-in-vxworks-6-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!