当前位置: 技术问答>linux和unix
请哪位高手帮忙看看这个程序哪里错了!
来源: 互联网 发布时间:2016-08-29
本文导语: #include #include #include #include #include #include #include int main(int argc,char **argv) { FILE *fp; int fds[2]; char *arg_list[] = {"ls",NULL}; char *arg_list1[] = {"wc",NULL}; pid_t pid,pid1; char *line = NULL; size_t n; pipe(fds); fp =fopen(argv[1],...
#include
#include
#include
#include
#include
#include
#include
int main(int argc,char **argv)
{
FILE *fp;
int fds[2];
char *arg_list[] = {"ls",NULL};
char *arg_list1[] = {"wc",NULL};
pid_t pid,pid1;
char *line = NULL;
size_t n;
pipe(fds);
fp =fopen(argv[1],"r");
while(getline(&line,&n,fp) != EOF)
{
pid1= fork();
if(pid1 == 0)
{
if(strchr(line,'|'))
{
pid = fork();
if(pid == 0)
{
close(fds[0]);
dup2(fds[1],1);
execvp("ls",arg_list);
}
else
{
close(fds[1]);
dup2(fds[0],0);
execvp("wc",arg_list1);
}
}
}
line = NULL;
}
return 0;
}
#include
#include
#include
#include
#include
#include
int main(int argc,char **argv)
{
FILE *fp;
int fds[2];
char *arg_list[] = {"ls",NULL};
char *arg_list1[] = {"wc",NULL};
pid_t pid,pid1;
char *line = NULL;
size_t n;
pipe(fds);
fp =fopen(argv[1],"r");
while(getline(&line,&n,fp) != EOF)
{
pid1= fork();
if(pid1 == 0)
{
if(strchr(line,'|'))
{
pid = fork();
if(pid == 0)
{
close(fds[0]);
dup2(fds[1],1);
execvp("ls",arg_list);
}
else
{
close(fds[1]);
dup2(fds[0],0);
execvp("wc",arg_list1);
}
}
}
line = NULL;
}
return 0;
}
|
c里面没有getline(&line,&n,fp)这个函数,这是c++中ifstream的
其他的错误楼主自己说明一下
其他的错误楼主自己说明一下
|
还有贴代码请用“插入源代码”。。。今天几个提问的都是直接粘贴,我看都懒得看了。。。