3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Add to readline cmdline-editing by
7 * JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
9 * SPDX-License-Identifier: GPL-2.0+
18 * Run a command using the selected parser.
20 * @param cmd Command to run
21 * @param flag Execution flags (CMD_FLAG_...)
22 * @return 0 on success, or != 0 on error.
24 int run_command(const char *cmd, int flag)
26 #ifndef CONFIG_SYS_HUSH_PARSER
28 * cli_run_command can return 0 or 1 for success, so clean up
31 if (cli_simple_run_command(cmd, flag) == -1)
36 return parse_string_outer(cmd,
37 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
41 int run_command_list(const char *cmd, int len, int flag)
44 char *buff = (char *)cmd; /* cast away const */
49 #ifdef CONFIG_SYS_HUSH_PARSER
50 /* hush will never change our string */
53 /* the built-in parser will change our string if it sees \n */
54 need_buff = strchr(cmd, '\n') != NULL;
58 buff = malloc(len + 1);
61 memcpy(buff, cmd, len);
64 #ifdef CONFIG_SYS_HUSH_PARSER
65 rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
68 * This function will overwrite any \n it sees with a \0, which
69 * is why it can't work with a const char *. Here we are making
70 * using of internal knowledge of this function, to avoid always
71 * doing a malloc() which is actually required only in a case that
74 rcode = cli_simple_run_command_list(buff, flag);
82 /****************************************************************************/
84 #if defined(CONFIG_CMD_RUN)
85 int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
92 for (i = 1; i < argc; ++i) {
95 arg = getenv(argv[i]);
97 printf("## Error: \"%s\" not defined\n", argv[i]);
101 if (run_command(arg, flag) != 0)