getOutputStream() works only once
Hello,
I have the following code:
Launches a cpp program.
Quote:
cpp = runtime.exec(cmds);
And this is the java code
Code:
try
{
cpin =new BufferedInputStream(new DataOutputStream(cpp.getOutputStream()));
cpin.write('a');
cpin.close();
}
catch(IOException err)
{ Const.error(err); }
The problem is that if I call this function twice (the cpp it is initialized only once), oddly my program in C + + does not read the result of write ().I thought that doing a flush () first and then a close () at the very end would be a solution but nothing came of it. I think the getOutputStream() works only once in the program.
Re: getOutputStream() works only once
Hi,
I think it comes from the close (), when you close the input stream a prior you can not reopen it. I think you should write the data twice on the tide. And remember one think if you do not close it properly at the correct time then the data will not be sent even if you try to flush it from there. Other than this I think I do not a have a solution for this.
Re: getOutputStream() works only once
Hello
See, if removing the buffering may help you. Something like this, here is the code.
Quote:
cpp =new DataOutputStream(cpp.getOutputStream());
I have not tried it, but see if this works with your code. I think this shoudl work fine with the code and the program should not give nay problem which compiling and running.
Re: getOutputStream() works only once
Hello,
Thanks you for your advice, but that did not worked well. I think I'll use another method of communication between my code in C + + and Java in my code when two separate shipments must be made. For what I believe is that there is no solution (the JVM is apparently not capable of sending data to a stream without closing it). If you know any other logic than this then please let me know.
Re: getOutputStream() works only once
Hello,
In fact there is already a buffer in the stream that you retrieve with Process.getOutputStream (), so it must anyway be a flush (). If not for your comment on the JVM in general when you reach such a conclusion on something very basic, the problem is rather in your code, may be part of the C++ code? There NYI if that is specifically made for this kind of problem.
Re: getOutputStream() works only once
Hello,
Quote:
If not for your comment on the JVM in general when you reach such a conclusion on something very basic, the problem is rather in your code, may be part of the C + +?
I made many tests and I am quite sure that the data flow are not sent by the java code before the close (). Hence the problem.
Quote:
There NYI if that is specifically made for this kind of problem.
Really? It is part of the API by default?