#include
#include
#include
#include
int system(const char * cmdstring)
...{
pid_t pid;
int status;
if(cmdstring == NULL)...{
return (1);
}
if((pid = fork())<0)...{
status = -1;
}
else if(pid == 0)...{ //子进中运行脚本命令
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
-exit(127); //子进程正常执行则不会执行此语句
}
else...{ //父进程中等待子进程返回
while(waitpid(pid, &status, 0) < 0)...{
if(errno != EINTER)...{
status = -1;
break;
}
}
}
return status;
}
阅读(380) | 评论(0) | 转发(0) |