9 start命令(harib23i)
今天时间也不早了,差不多该结束了,不过30天大限将至,我们还剩好多东西没有做呢,因此今天大家就辛苦一下,再努把力吧。
我们在26.5节中提起过,Windows的命令行窗口里有一个start命令,它的功能是可以打开一个新的命令行窗口并运行指定的应用程序。讲这么多不如自己实践一下,在Windows中输入“start make run”试试看吧。
如果“纸娃娃系统”也有这个功能该多方便啊,那我们就来编写一个start命令吧。
本次的console.c节选
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
{
(省略)
} else if (strncmp(cmdline, "start ", 6) == 0) {
cmd_start(cons, cmdline, memtotal);
} else if (cmdline[0] != 0) {
(省略)
}
void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal)
{
struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
struct SHEET *sht = open_console(shtctl, memtotal);
struct FIFO32 *fifo = &sht->task->fifo;
int i;
sheet_slide(sht, 32, 4);
sheet_updown(sht, shtctl->top);
/*将命令行输入的字符串逐字复制到新的命令行窗口中*/
for (i = 6; cmdline[i] != 0; i++) {
fifo32_put(fifo, cmdline[i] + 256);
}
fifo32_put(fifo, 10 + 256); /*回车键*/
cons_newline(cons);
return;
}
好,完工了,很简单吧。我们来“make run”,输入“start color2”……哦,成功了!
![]() | ![]() | |
执行start命令 | 执行后的样子 |