Thread: How to read the execl() output?

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    4

    How to read the execl() output?

    Which is the best way of getting the output from an execl() call? This call generates some console output and I need to do some kind of capture.

    Thanks,

    Daniel.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Pipe it.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    4
    Thanks Quzah for your reply.

    Does freopen use pipes?
    I'm doing

    FILE* fpStdout = freopen(STDOUTFILE, "w+", stdout);
    system("ls");

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    FILE *fp = popen("ls","r");
    pclose(fp);
    Then use fgets() like you would for any other regular file.

    Is "ls" just an example, or are you really trying to use ls to get a directory listing into the program?
    If so, look up opendir / readdir / closedir
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 02:18 AM
  2. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  3. Replies: 1
    Last Post: 12-31-2001, 05:04 PM
  4. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM
  5. To all who read last post formatted output
    By spliff in forum C Programming
    Replies: 8
    Last Post: 08-21-2001, 03:37 AM