execl() problem in C under unix 
Author Message
 execl() problem in C under unix

Hi, I hope this is the right newsgroup for question, otherwise, excuse me.
Here's my problem: I want to use the unistd.h execl() with pipes, like:

execl("/usr/bin/cat","cat","fbrev.txt","|","/usr/lib/sendmail","-t",recepient,NULL);
And it returns endless junk-text...
Seems the problem is with the pipe |, does anyone know how to use pipes in
execl() ? Is there a way around ?

Thanks in advance, Martin Fredricsson



Tue, 06 Jun 2000 03:00:00 GMT  
 execl() problem in C under unix



Quote:
>Hi, I hope this is the right newsgroup for question, ...

Nope.

Quote:
>Here's my problem: I want to use the unistd.h execl() with pipes, like:

>execl("/usr/bin/cat","cat","fbrev.txt","|","/usr/lib/sendmail","-t",recepient,NULL);
>And it returns endless junk-text...
>Seems the problem is with the pipe |, does anyone know how to use pipes in
>execl() ? Is there a way around ?

If you want to set up a pipeline, you need to do a lot more work.
Look in the manual for exec(2), pipe(2), dup(2), close(2), exit(2).
For a good guide to general UNIX programming, I recommend Kernighan
& Pike's "The UNIX Programming Environment".

If you want to communicate on one end of a pipe with a process you
initiate, check out popen(3).

If all you really want to do is spawn a pipeline with which your
process will not interact, use the system(3) function instead.



Tue, 06 Jun 2000 03:00:00 GMT  
 execl() problem in C under unix

Quote:

>Hi, I hope this is the right newsgroup for question, otherwise, excuse me.
>Here's my problem: I want to use the unistd.h execl() with pipes, like:

>execl("/usr/bin/cat","cat","fbrev.txt","|","/usr/lib/sendmail","-t",recepient,NULL);
>And it returns endless junk-text...
>Seems the problem is with the pipe |, does anyone know how to use pipes in
>execl() ? Is there a way around ?

For this example it might be better and simpler to use the system ()
function.

result = system ("/usr/bin/cat fbrev.txt | /usr/lib/sendmail -t");

or

char cmdline[1024];
sprintf (cmdline, "/usr/bin/cat fbrev.txt | /usr/lib/sendmail %s",
recipient);

result = system (cmdline);

As a side remark: sendmail -t causes the reciver list to be deducted from
the mail message itself.

If you want ot use execl you need to create two processes, one for the cat
command and one for sendmail. Then you need to create a pipe between these
two processes.  The details of how to do that is better asked in a unix
group.  

Villy



Tue, 06 Jun 2000 03:00:00 GMT  
 execl() problem in C under unix

Quote:

>Hi, I hope this is the right newsgroup for question, otherwise, excuse me.
>Here's my problem: I want to use the unistd.h execl() with pipes, like:

>execl("/usr/bin/cat","cat","fbrev.txt","|","/usr/lib/sendmail","-t",recepient,
>NULL);
>And it returns endless junk-text...
>Seems the problem is with the pipe |, does anyone know how to use pipes in
>execl() ? Is there a way around ?

You have received some answers to this nevertheless you should be aware that
your question is about the Unix/POSIX function execl() and Unix/POSIX pipes
and isn't about the C language. A much better newsgroup to post this in
would have been comp.unix.programmer.

--
-----------------------------------------


-----------------------------------------



Thu, 08 Jun 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. execl,execv ... starting a UNIX-shell procedure

2. Newbie: separate big .cs file into small .cs files

3. Problem #30 on http://cs.nmu.edu/programming/c/problems.htm

4. Problems using system() and execl() - Please Help

5. Specifying a variable path to execl()

6. execl mem requirement

7. EXECL ()

8. execl and then return

9. malloc and execl

10. execl(), and other program executing functions...

11. execl()

12. execl - call with redirections

 

 
Powered by phpBB® Forum Software