[msh]执行小程序

This commit is contained in:
heyuanjie 2018-07-02 13:47:47 +08:00
parent 9df6acc067
commit 409e7fca0a
1 changed files with 45 additions and 0 deletions

View File

@ -313,6 +313,44 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
return 0;
}
#if defined(RT_USING_LWP) && defined(RT_USING_DFS)
static int _msh_exec_lwp(char *cmd, rt_size_t length)
{
int argc;
int cmd0_size = 0;
char *argv[FINSH_ARG_MAX];
int fd = -1;
char *pg_name;
extern int exec(char*, int, char**);
/* find the size of first command */
while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length)
cmd0_size ++;
if (cmd0_size == 0)
return -1;
/* split arguments */
rt_memset(argv, 0x00, sizeof(argv));
argc = msh_split(cmd, length, argv);
if (argc == 0)
return -1;
pg_name = argv[0];
/* try to open program */
fd = open(pg_name, O_RDONLY, 0);
if (fd < 0)
return -1;
/* found program */
close(fd);
exec(pg_name, argc, argv);
return 0;
}
#endif
int msh_exec(char *cmd, rt_size_t length)
{
int cmd_ret;
@ -356,6 +394,13 @@ int msh_exec(char *cmd, rt_size_t length)
}
#endif
#if defined(RT_USING_LWP) && defined(RT_USING_DFS)
if (_msh_exec_lwp(cmd, length) == 0)
{
return 0;
}
#endif
/* truncate the cmd at the first space. */
{
char *tcmd;