View Full Version : allowing pipes with execution in C
mungyun
04-11-2002, 04:33 PM
i'm having a heck of a time trying to figure out if i can execute a program, say using execl or similar and using a pipe with that.
ex. i want to print the file size of /home/foo/foo.txt by running
ls -al /home/foo/foo.txt|gawk '{print $5}'
how would i go about doing this? is it even possible? (duh, of course it is... somehow).
Deckard
04-12-2002, 12:32 PM
Keeping mind that pipes and redirects are a function of the shell, here are a couple of things to try:
1) Use system() to execute the command.
2) If you must use execl(), exec the shell (/bin/bash, /bin/ksh, etc) and pass your command as the sole argument.
3) Put you command in a shell script which you can call from execl().
Salem
04-12-2002, 02:08 PM
There are far more efficient ways of getting the file size.
But for pipes, you need to look up the pipe system call, and arrange for a pipe to exist between two child processes.
klausi
04-13-2002, 05:53 AM
There are far more efficient ways of getting the file size.
unsigned long sizeoffile(FILE *file)
{
fseek(file,0,SEEK_END);
return(ftell(file));
}
klausi
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.