how to use system function to execute the script
bin.wang at qkmtech.com
bin.wang at qkmtech.com
Fri Jun 22 07:05:54 UTC 2018
hi chris
where is rtems_shell_execute_cmd function defined?
best ben
bin.wang at qkmtech.com
From: Chris Johns
Date: 2018-06-22 13:07
To: bin.wang at qkmtech.com; Users
Subject: Re: how to use system function to execute the script
On 22/06/2018 14:44, bin.wang at qkmtech.com wrote:
> hi everyone:
>
> i want to use the "system()" to execute the script. but do not has output
>
> first i want to use "system()" to execute the shell cmd, but alse have no output
>
> the test code is as followed:
>
> system("ls -l");
> system("joel /flash/script/spdloop_1"); //
> "/flash/script/spdloop_1"----------this is the script file path in the filesystem
>
RTEMS is a single address space, single process OS so you can not exec another
process. You can call the shell command handler from any thread. Make sure you
have enough stack for the thread.
Try something like:
int run_shell_command(const char* cmd)
{
#define CMD_MAX_ARGS (20)
char* cmd_argv = strdup(cmd);
int argc;
char* argv[CMD_MAX_ARGS];
int r;
if (cmd_argv == NULL) {
fprintf(stderr, "shell: command: no memory: %s", cmd);
return 1;
}
if (rtems_shell_make_args(cmd_argv, &argc, argv, CMD_MAX_ARGS) < 0) {
fprintf(stderr, "shell: command: arg parse: %s", cmd);
free(cmd_argv);
return 1;
}
r = rtems_shell_execute_cmd(argv[0], argc, argv);
free(cmd_argv);
return r;
}
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20180622/bba98a4b/attachment-0002.html>
More information about the users
mailing list