allowing pipes with execution in C

This is a discussion on allowing pipes with execution in C within the Linux Programming forums, part of the Platform Specific Boards category; i'm having a heck of a time trying to figure out if i can execute a program, say using execl ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    6

    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
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    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
    Posts
    197
    There are far more efficient ways of getting the file size.
    Code:
    unsigned long sizeoffile(FILE *file)
    {
      fseek(file,0,SEEK_END);
      return(ftell(file));
    }
    klausi
    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, 06:17 AM
  5. Services and Pipes
    By nickname_changed in forum Windows Programming
    Replies: 0
    Last Post: 07-16-2003, 06:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21