![]() |
|
Communication |
ImLeftFooted
Member #3,935
October 2003
![]() |
So Program A on exit has to start up Program B and pass some text-based information to it. What is the best way to do this? The applications will be running on windows so using something windows-specific is a possibility, but if its just as easy I'd like to do it in a portable fashion. |
kazzmir
Member #1,786
December 2001
![]() |
Command line arguments? |
X-G
Member #856
December 2000
![]() |
If you only need to give it the data once at the start, command line arguments. Otherwise, look into named pipes or some other inter-process communication protocol. -- |
ImLeftFooted
Member #3,935
October 2003
![]() |
Command Line would be easiest, but doesn't it have some static limit? |
Sevalecan
Member #4,686
June 2004
![]() |
Something like that. Pipes would be better for binary or large amounts of data. And as far as ease goes... At least they aren't tcp sockets, which are a royal pain in the ass(of course, you could use them.... if you were masochist). TeamTerradactyl: SevalecanDragon: I should shoot you for even CONSIDERING coding like that, but I was ROFLing too hard to stand up. I love it! |
X-G
Member #856
December 2000
![]() |
You really should tell us what kind of data and how much you need to pass. The correct method depends on these factors. -- |
Carrus85
Member #2,633
August 2002
![]() |
Quote: So Program A on exit has to start up Program B and pass some text-based information to it. What is the best way to do this? The applications will be running on windows so using something windows-specific is a possibility, but if its just as easy I'd like to do it in a portable fashion. On nix, exec* works nicely. On Windows, it looks like exec exists, but I'm not sure it behaves exactly the same way as it does on nix. (exec on nix replaces the current process image with the given process image and starts execution, effectively replacing the current process with a completely separate process (that has the same Process ID as the "parent" process)) As for Program B text arguments, exec maintains the file descriptors across the two "processes", allowing you to freopen on say, stdin, for example (allowing redirection). (Once again, *nix programming, not sure of the windows equivalents (or if the windows equivalents work the same way).
|
ImLeftFooted
Member #3,935
October 2003
![]() |
The data is going to be in this format: "Descr"{"blah") "descr two"{"blah":"0","blah2":"1"}
|
kazzmir
Member #1,786
December 2001
![]() |
Write it to a file and give the file as a command line argument. |
ImLeftFooted
Member #3,935
October 2003
![]() |
What about concurrency issues? Also where to write the file? What if the program does not have permissions to write to a given folder. Finding the proper folder to write stuff is a battle I'd rather not fight.. [update] [update 2]
I left room for implementations on other platforms. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
And in unix it can be as easy as "named pipes" (a special file that both processes open), or the "pipe" function which returns two file handles which correspond to each end of the pipe. -- |
kazzmir
Member #1,786
December 2001
![]() |
Maybe it would be easier to just open up a socket and write to that? |
ImLeftFooted
Member #3,935
October 2003
![]() |
Ya probably. But using a pipe like this handles concurrency in the best possible way. So sockets would be easier but pipes would be less evil. |
|