running a program with a program

This is a discussion on running a program with a program within the C Programming forums, part of the General Programming Boards category; I am looking to run the labrea program from within a program I am creating in one thread and posting ...

  1. #1
    Gentoo System .......... Doorsdown's Avatar
    Join Date
    May 2007
    Location
    Rhode Island, USA
    Posts
    19

    running a program with a program

    I am looking to run the labrea program from within a program I am creating in one thread and posting the data into the database in another. I need to be able to launch the program with its args and receive the data it will be outputting so I can place that into a structure. I have taken a look at the FAQ but it didn't mention how I could get it to retrieve the output from the subprocess.
    Last edited by Doorsdown; 10-15-2007 at 09:59 PM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Do you mean to read from the stdout of the child process?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Gentoo System .......... Doorsdown's Avatar
    Join Date
    May 2007
    Location
    Rhode Island, USA
    Posts
    19
    yes i do

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    one way to do it
    system("myprog > tempfile");
    and then read the tempfile
    there are more advanced ways of doing the same - you can search the forum
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    It's really platform specific, if you're looking for a Win32 solution you can create a child process with inherited stdout, stdin and stderr handles (from the parent) with CreateProcess().

  6. #6
    Gentoo System .......... Doorsdown's Avatar
    Join Date
    May 2007
    Location
    Rhode Island, USA
    Posts
    19
    I'm looking for a POSIX solution, win32 is not even being considered. Its Current method works off of a temp file and that is one key thing I am trying to avoid.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What about popen()

    man popen

    There's also a _popen in windows, that apparently does the same thing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program running long
    By smarta_982002 in forum Windows Programming
    Replies: 3
    Last Post: 03-27-2008, 05:24 AM
  2. Running my program in the background
    By shoobsie in forum Windows Programming
    Replies: 4
    Last Post: 10-09-2005, 02:38 AM
  3. Replies: 3
    Last Post: 09-05-2005, 08:57 AM
  4. Why is my program running away?
    By badkitty in forum C++ Programming
    Replies: 4
    Last Post: 09-19-2001, 04:27 PM
  5. Running program
    By muffin in forum C Programming
    Replies: 5
    Last Post: 08-30-2001, 10:57 AM

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