所以我想定义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)
在这种情况下不做任何事情.我究竟做错了什么?