Skip to content

Instantly share code, notes, and snippets.

@kcbarry
Last active December 16, 2015 20:29
Show Gist options
  • Save kcbarry/5492900 to your computer and use it in GitHub Desktop.
Save kcbarry/5492900 to your computer and use it in GitHub Desktop.
A quick and dirty way to run commands on weenix without a terminal
Add this to the end of kernel/test/kshell/kshell.c and declare it in the associated .h
int kshell_test(kshell_t *ksh,char *command)
{
char *args[10];
int argc = 0;
char redirect_in[MAXPATHLEN];
char redirect_out[MAXPATHLEN];
int append;
redirect_in[0] = redirect_out[0] = '\0';
kshell_find_redirection(ksh, command, redirect_in, redirect_out, &append );
kshell_redirect(ksh, redirect_in, redirect_out, append);
kshell_get_args(ksh, command, args, KSH_MAX_ARGS, &argc);
kshell_command_t *cmd;
if ((cmd = kshell_lookup_command(args[0], strlen(args[0]))) == NULL) {
kprintf(ksh, "kshell: %s not a valid command\n", args[0]);
} else {
cmd->kc_cmd_func(ksh, argc, args);
}
kshell_undirect(ksh);
return 0;
}
Run the command in the kernel/main/kmain.c after we construct the kshell.
Insert the following function call about line 365
kshell_test(kshell,"echo foo > short \n");
kshell_test(kshell,"cat short \n");
Also, if you want to test exit. Comment out the kshell loop.
/*while (kshell_execute_next(kshell));*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment