📄 execfile.c
字号:
#include "dispatch.h"
const char *env_init[]={"USER=unknow","PATH=/tmp",NULL}; //执行文件标识
int DISPATCH_Exec(const char *pathname)
{
pid_t pid;
int fd[2];
if (pipe(fd)<0)
{
printf("pipe error\r\n");
return -1;
}
if ((pid=fork())<0)
{
printf("fork error\r\n");
return -1;
}
else if (pid==0)
{
//if (execle(pathname,"ppp","myarg1","MY ARG1",(char *)0,env_init)<0)
close(fd[1]);
if(fd[0]!=STDIN_FILENO)
{
if(dup2(fd[0],STDIN_FILENO)!=STDIN_FILENO)
{
close(fd[0]);
printf("dup2 error\r\n");
return -1;
}
}
if (system(pathname)<0)
{
printf("system error\r\n");
return -1;
}
exit(0);
}
// else
/*
if (waitpid(pid,NULL,0)<0)
{
printf("wait error\r\n");
return -1;
}
if ((pid=fork())<0)
{
printf("fork error\r\n");
return -1;
}
else if (pid==0)
{
if (system(pathname)<0)
{
printf("system error\r\n");
return -1;
}
}*/
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -