<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 微软雅黑; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>thanks,it works</div>
<div><br></div><hr style="width: 210px; height: 1px;" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div>bin.wang@qkmtech.com</div></div></span></div>
<blockquote style="margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;"><div> </div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>From:</b> <a href="mailto:chrisj@rtems.org">Chris Johns</a></div><div><b>Date:</b> 2018-06-22 13:07</div><div><b>To:</b> <a href="mailto:bin.wang@qkmtech.com">bin.wang@qkmtech.com</a>; <a href="mailto:users@rtems.org">Users</a></div><div><b>Subject:</b> Re: how to use system function to execute the script</div></div></div><div><div>On 22/06/2018 14:44, bin.wang@qkmtech.com wrote:</div>
<div>> hi everyone:</div>
<div>> </div>
<div>> i want to use the "system()" to execute the script. but do not has output</div>
<div>> </div>
<div>> first i want to use "system()" to execute the shell cmd, but alse have no output</div>
<div>> </div>
<div>> the test code is as followed:</div>
<div>> </div>
<div>>     system("ls -l");</div>
<div>>     system("joel /flash/script/spdloop_1");    //</div>
<div>>  "/flash/script/spdloop_1"----------this is the  script file path in the filesystem </div>
<div>>   </div>
<div> </div>
<div>RTEMS is a single address space, single process OS so you can not exec another</div>
<div>process. You can call the shell command handler from any thread. Make sure you</div>
<div>have enough stack for the thread.</div>
<div> </div>
<div>Try something like:</div>
<div> </div>
<div>int run_shell_command(const char* cmd)</div>
<div>{</div>
<div>  #define CMD_MAX_ARGS (20)</div>
<div>  char* cmd_argv = strdup(cmd);</div>
<div>  int   argc;</div>
<div>  char* argv[CMD_MAX_ARGS];</div>
<div>  int   r;</div>
<div> </div>
<div>  if (cmd_argv == NULL) {</div>
<div>    fprintf(stderr, "shell: command: no memory: %s", cmd);</div>
<div>    return 1;</div>
<div>  }</div>
<div> </div>
<div>  if (rtems_shell_make_args(cmd_argv, &argc, argv, CMD_MAX_ARGS) < 0) {</div>
<div>    fprintf(stderr, "shell: command: arg parse: %s", cmd);</div>
<div>    free(cmd_argv);</div>
<div>    return 1;</div>
<div>  }</div>
<div> </div>
<div>  r = rtems_shell_execute_cmd(argv[0], argc, argv);</div>
<div>  free(cmd_argv);</div>
<div>  return r;</div>
<div>}</div>
<div> </div>
<div>Chris</div>
<div> </div>
</div></blockquote>
</body></html>