-
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.
-
popen() is part of Posix and should work on both - assuming you're using GCC and its standard libs.
gg
-
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.
-
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
-
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.