Thread: Calling a subprogram

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    26

    Calling a subprogram

    Hello,

    Here's my problem. I have some existing programs, but I want to replace a single function call in Program A, with a completely separate Program B. I can't just implement program B as a sub-routine, even though I wish I could.

    So my question is how would I go about calling a program from within another program. I did some searching and found popen() and CreateProcess(), but I believe those are good only on Windows. I'm using both an intel mac (w/ leopard) and linux. A cross-platform solution would be ideal, although I know this is unlikely. Both program A and program B are command line programs.

    Any Ideas?

    Thanks

    EDIT: Did some more searching, it seems like the commands I will use will probably be somewhere along the lines of System, exec, or Fork, and maybe still pOpen(). I'm still not really sure how to handle passing data between the two programs, since I will have quite a good amount of arrays and such that will need to be passed both directions. Any help is appreciated.
    Last edited by moddinati; 07-01-2008 at 11:28 AM. Reason: fixed grammar

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    popen() is part of Posix and should work on both - assuming you're using GCC and its standard libs.

    gg

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    26
    ok thanks.

    Is the only way to pass data is read/write every piece of data to the stream, or is there an eaiser way? Especially for passing things like multi-dimensional arrays.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    If you have the source to both applications, there are a hand-full of inter-process communication techniques:
    - Streams/Pipes (popen())
    - Sockets
    - Message Queue's
    - Shared Memory

    >> or is there an easier way
    In terms of a learning-curve, pipes are probably the easiest.

    gg

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    26
    I will have to look more into those. I do have access to both sources. I'm just looking for the quickest solution, so I will probably use pipes.

    Thanks for the help, its much appreciated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack issues when calling a COM library
    By notnot in forum C Programming
    Replies: 3
    Last Post: 06-01-2009, 02:12 AM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. calling default instead of argument constructor, why?!
    By cppn00b in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2005, 04:24 AM
  4. calling conventions
    By Micko in forum C Programming
    Replies: 2
    Last Post: 07-18-2004, 09:13 AM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 05:32 PM