尝试制作Bootleg终端模拟器时,ls命令不起作用

时间:2019-05-15 08:24:49

标签: c terminal

我正在尝试制作一个Bootleg终端模拟器,但是遇到了问题  实施ls命令

基本上,这个ls命令应该像通常一样打印出当前“目录”中的文件,但是不会,这是我的代码:

void ls()
{
    int pid;            //process id
    pid = fork();     //create another process
    if ( pid < 0 )
    {                                 
        printf("\nFork failed\n");
        exit (-1);
    }
    else if ( pid == 0 )
    {                     
        execlp ( "/bin/ls", "ls", "-l", NULL ); 
    }
    else
    {                             
        wait (NULL);             
        printf("\nchild complete\n");
        exit (0);
    }
}

int main()
{
    char input[999];

    scanf("%200s", input);
    if (input == "ls")
    {
        ls();
    }
    return 0;
}

我输入ls,它应该做它的事,但是不会,它不需要输入命令就可以工作,但是我不能只拥有一个执行ls的程序。

0 个答案:

没有答案