Communication between a C++ and Java program?

T

Tyler

Hi ppl,

I know it's forbidden to mention Java in this newsgroup but I've been
presented with a problem which requires that my C++ program
communicate with another java program.

What is the best,simplest and quickest way to go about this?

I was thinking, I could have my C++ program write data to a file and
then my Java program pick it up from there but this is a little too
slow for my needs. What about writing to an environment variable in
the OS? I know java can do that but can C++ do that? Any ideas
anyone?

Many thanks.

Tyler
 
D

Dirk Feytons

Tyler said:
I know it's forbidden to mention Java in this newsgroup but I've been
presented with a problem which requires that my C++ program
communicate with another java program.

What is the best,simplest and quickest way to go about this?

How about using sockets?

--
Dirk

(PGP keyID: 0x448BC5DD - http://www.gnupg.org - http://www.pgp.com)

..oO° "I've seen things you people wouldn't believe. Attack ships on fire
off the shoulder of Orion. I watched C-beams glitter in the dark near
the Tannhauser gate. All those moments will be lost in time, like tears
in rain. Time to die." -- Blade Runner °Oo.
 
F

Frank Schmitt

Hi ppl,

I know it's forbidden to mention Java in this newsgroup but I've been
presented with a problem which requires that my C++ program
communicate with another java program.

What is the best,simplest and quickest way to go about this?

I was thinking, I could have my C++ program write data to a file and
then my Java program pick it up from there but this is a little too
slow for my needs. What about writing to an environment variable in
the OS? I know java can do that but can C++ do that? Any ideas
anyone?

Some ideas (none tested):

- use a shared memory segment (man shmget on Unix)
- if your java program just needs the data from the C++ program, use
a pipe
- use Javas JNI facility
- use a framework like CORBA

Of course, all of these are OT in comp.lang.c++ :)

HTH & kind regards
frank
 
E

Eric Boutin

maybe system("java programname > ./tmpfile") then parse ./tmpfile ?

this is almost std c++.. the only issue that is not standard is stdout
redirection in the system function, but this program will compile on any
implentation.. and almost all OS support > to redirect stdout.. not big
deal.. or you could also create a file with all the data the java program
need, pass it to the program as a command line argument, then redirect the
output and parse it.. but be shure both files are in ansci mode.. and no,
passing a pointer to the other program is not a good idea.

hope it help

-Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top