Compilation Error in i/o redirection in C program in linux -


i'm trying make simple i/o redirection(ls sort)(ls|sort>f1) , next step direct output of sort file in c when compiling gcc giving following error..plz me :)

code

#include<stdio.h> #include<fcntl.h> #include<string.h> #include<stdlib.h> #include<sys/types.h> #include<unistd.h> int main() { int a,b,c,d,pfd[2],kk,i,j; file *fp;  i=fork(); if(i==0) {     pipe(pfd);     j=fork();     if(j==0)     {         close(1);         dup(pfd[1]);         close(pfd[0]);         close(pfd[1]);         excel("/bin/ls","/ls",0);     }     else     {         close(0);         dup(pfd[0]);         close(pfd[0]);         close(pfd[1]);         /*close(1);         kk=open(f.txt,o_wronly);         dup(kk);         */         excel("/usr/bin/sort","/sort",0);     } } else     wait(); /*char k[100],pp[100],ll[]="/bin/"; printf("enter cmd execut"); scanf("%s",k); strcpy(pp,k); strcat(ll,k); printf("%s",ll); system(ll);*/     return 0; } 

error:

/tmp/cc6wivoj.o:

in function **main**: j.c:(.text+0x81): undefined reference **excel**  j.c:(.text+0xcf): undefined reference **excel**  collect2: error: ld returned 1 exit status 

there bogus answers here can't comment on since don't have '50 reputation' points. hence entirely new reply instead.

as correctly noted people have typo, want execl instead of excel.

however, people claim execl system call. not. it's convenience function in libc. syscall executed @ end of day execve, can confirm e.g. using strace.

there several issues code, have warnings enabled when compile? -wall -wextra gcc out.

example issues: - wait() takes argument, , warned if had proper header files included - missing error checking (fork, pipe, wait)

in general coding style lead trouble.

always include relevant headers (to found in manpages) , check return values.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -