data sharing between 2 c++ programs
Hi,
I would like to pass some values from a program to another program, in c++;
for example if in the first program i have a variable called x which changes its value every time, and I want to take this value and pass it to the variable called y, which is in the second program. Is there an easy way to do that ? I tried with sockets, but i'm not that skilled and I want to try an easier method. With files maybe ? Some code would help me a lot.
Note that x changes its value very quickly.
Thank you
Re: data sharing between 2 c++ programs
Pipes may be what you're looking for.
You can use shared memory, too. Actually, pipes are usually implemented using shared memory.
Re: data sharing between 2 c++ programs
Thank you for your advice, but can you help me with some piece of code ?
I found this with google, but it copies an output from a shell, to a file:
char line[100];
in=popen("ls -l", "r");
FILE * out = fopen("filename", "w");
while(fgets(line, sizeof line, in))
fprintf(out, "%s" line);
fclose(out);
What i want is to take the value of a variable from a first program and assign it to another variable from another program; both programs will run in the same time..
Thanks
Re: data sharing between 2 c++ programs
If you're using popen() I presume you're on Linux. (At least, I don't think that's a cross-platform function....is it?)
If so, you may find this useful:
http://fscked.org/writings/SHM/shm.html
Re: data sharing between 2 c++ programs
It's not (cross-platform).
Smirk.
Re: data sharing between 2 c++ programs
Unfortunately there is no 100% cross-platform IPC method I'm aware of except writing to files. However, if you're willing to wrap up the API differences behind an abstraction layer, every platform has the same conceptual methods-----shared memory, pipes, and sockets, for the most part. Shared memory is the fastest.
Re: data sharing between 2 c++ programs
Quote:
Originally Posted by ariell
It's not (cross-platform).
Smirk.
http://msdn.microsoft.com/en-us/libr...4b(VS.80).aspx
Re: data sharing between 2 c++ programs
Nice learning from expect.
Inter Process Communication.
Re: data sharing between 2 c++ programs
I've managed to use IPC memory with functions like shmget, shmap which I found in a tutorial here : http://www.cs.cf.ac.uk/Dave/C/node27.html
Thanks a lot for the idea!
Re: data sharing between 2 c++ programs
Thanks for the link. I didn't know that MS spot.
Best from the south.