|
-
October 2nd, 2008, 12:20 PM
#1
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
-
October 2nd, 2008, 12:23 PM
#2
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.
-
October 2nd, 2008, 01:11 PM
#3
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
-
October 2nd, 2008, 01:18 PM
#4
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
-
October 2nd, 2008, 07:46 PM
#5
Re: data sharing between 2 c++ programs
It's not (cross-platform).
Smirk.
ariell
programming is understanding
-
October 2nd, 2008, 07:49 PM
#6
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.
-
October 2nd, 2008, 11:25 PM
#7
Re: data sharing between 2 c++ programs
 Originally Posted by ariell
It's not (cross-platform).
Smirk.
http://msdn.microsoft.com/en-us/libr...4b(VS.80).aspx
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
October 3rd, 2008, 04:22 AM
#8
Re: data sharing between 2 c++ programs
Nice learning from expect.
Inter Process Communication.
-
October 3rd, 2008, 01:51 PM
#9
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!
-
October 3rd, 2008, 02:06 PM
#10
Re: data sharing between 2 c++ programs
Thanks for the link. I didn't know that MS spot.
Best from the south.
ariell
programming is understanding
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|