IPC

hi. i'm new to java and i want to make my program interact with a C++ program and i'm having trouble with inter-process communication.

when i call Runtime.exec( C++ prog ) i get the Std input and output streams and use them to construct an InputStreamReader and OutputStreamWriter.

i can capture the output from the C++ prog, but when i send stuff TO it from the java program, it evidently doesnt do anything. should i be using something other than an OutputStreamWriter? there are so many different input and output objects, it's hard for me to know when to use which. or is there some more general flaw in my approach?

should i be using sockets? i didn't have any luck trying to find out about pipes in java...

[750 byte] By [spoongirl] at [2007-9-26 1:34:33]
# 1
check out this discussion: http://forums.java.sun.com/thread.jsp?forum=54&thread=147030
ldadams at 2007-6-29 2:17:50 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2

thanx- that was helpful

one difference though between that and what i'm trying to do is that i'm actually running the c++ program from the java program, as opposed to vice-versa.

i've made some progress, but i'm still having the problem that i can't seem to write to the stdin of the C++ prog. i get output from the program, but not the other way around. based on my experimentation, i think there's nothing wrong with the C++ code and it is in fact reading the input stream and finding nothing there.

i think perhaps i'm misusing the OutputStreamWriter. is there another Writer object that i should use, instead?

spoongirl at 2007-6-29 2:17:50 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3
once you write to the outputstream (that is inputstream for you C++ program) do flush() the output stream. If this doesn't help please paste the code where you get the C++ program's input and output streams and where you write data to C++ program.
msohaib at 2007-6-29 2:17:50 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4

thanx-

i did figure it out;

actually, the way i was trying to do the actual input and output was fine; it was just that i was doing the threading wrong, which was causing it to hang on the thread doing the input before it actually got a chance to do the output! (silly of me)

i just didn't have a clear understanding of how to use threads and i was directly calling the run() function instead of start()

spoongirl at 2007-6-29 2:17:50 > top of Java-index,Archived Forums,New To Java Technology Archive...