小编Bru*_*uno的帖子

如何定义系统()

所以我想定义system()函数!这是我的功能:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

void mySystem (char *command)
{    
    execlp (command, command, (char*) 0);
}

int main (int argc, char* argv[])
{    
    for (int i = 1; i < argc; i++) 
    {
        char command[50];
        strcpy(command, argv[i]);
        mySystem(command);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试它就像那样:

gcc exe6.c;
./a.out ls ls
Run Code Online (Sandbox Code Playgroud)

在这种情况下,它只做一个ls.

./a.out "ls -l"
Run Code Online (Sandbox Code Playgroud)

在这种情况下不做任何事情.我究竟做错了什么?

c bash operating-system

1
推荐指数
1
解决办法
72
查看次数

标签 统计

bash ×1

c ×1

operating-system ×1