Thread: allowing pipes with execution in C

  1. #1
    Registered User
    Join Date
    Apr 2002

    Angry allowing pipes with execution in C

    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).

  2. #2
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    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().
    Jason Deckard

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

  4. #4
    Registered User
    Join Date
    Oct 2001
    There are far more efficient ways of getting the file size.
    unsigned long sizeoffile(FILE *file)
    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pipes sometimes fail
    By EVOEx in forum Linux Programming
    Replies: 2
    Last Post: 05-02-2009, 01:47 PM
  2. Pipes
    By Martin Kovac in forum C Programming
    Replies: 1
    Last Post: 03-31-2009, 03:09 AM
  3. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  4. What is the best way to record a process execution time?
    By hanash in forum Linux Programming
    Replies: 7
    Last Post: 03-15-2006, 07:17 AM
  5. Services and Pipes
    By nickname_changed in forum Windows Programming
    Replies: 0
    Last Post: 07-16-2003, 06:46 AM