calling an external program + capture output?

This is a discussion on calling an external program + capture output? within the C++ Programming forums, part of the General Programming Boards category; Hi, Is it possible to run a program through the command interpreter and capture its output as well as the ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167

    calling an external program + capture output?

    Hi,
    Is it possible to run a program through the command interpreter and capture its output as well as the return code? (without having to resort to piping the output to a file and reading that file... as I would imagine it to be very expensive (as if calling the command interpreter is not expensive enough))

    I want it to be as efficient as possible. (can be Linux/POSIX-only, as it's a kind of low level thing)

    I am aware that doing something like this should be avoided for portability and performance among other reasons, but this is the only viable option in my case.

    What I am trying to do is to make a virtual versioned FUSE (filesystem in userspace) file system using git to do the hard work. There is indeed a libgit.a library, but it doesn't seem practical to use it currently because 1) as someone else pointed out, most of the git functions call exit() on error. and 2) there is no API documentation anywhere to be found.

    Thank you

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    popen() / pclose() should do the trick.

    gg

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    popen() / pclose() should do the trick.
    Exactly what I was looking for. Many thanks.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    Quote Originally Posted by cyberfish View Post
    Exactly what I was looking for. Many thanks.
    Just remember they aren't standard. You said Linux/POSIX but it pays to know.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Yes, I am aware of that. Thanks for the reminder.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Calling external program and reading its output.
    By Dragoon_42 in forum C++ Programming
    Replies: 3
    Last Post: 10-18-2007, 05:34 AM
  3. forcing stdout of external program to be line-buffered
    By FreakCERS in forum C Programming
    Replies: 4
    Last Post: 09-17-2006, 12:46 PM
  4. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 02:01 PM

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