Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



getOutputStream() works only once

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-01-2010
Member
 
Join Date: Dec 2009
Posts: 296
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.

Reply With Quote
  #2  
Old 28-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #3  
Old 28-01-2010
Member
 
Join Date: May 2008
Posts: 2,382
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 28-01-2010
Member
 
Join Date: Dec 2009
Posts: 296
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.
Reply With Quote
  #5  
Old 28-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #6  
Old 28-01-2010
Member
 
Join Date: Dec 2009
Posts: 296
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?
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "getOutputStream() works only once"
Thread Thread Starter Forum Replies Last Post
How does VPN Works Culpritism Networking & Security 1 03-12-2011 03:18 PM
Google translate hover function works in Internet Explorer but doesn’t works any longer in Chrome Pranvi Technology & Internet 5 26-08-2011 10:31 PM
How does JDK 5.0 works Langward Software Development 5 14-02-2010 04:00 AM
How to import from 7.0 works calender to 8.5 works calender? migons Windows Software 3 19-08-2009 07:21 PM
ITunes doesn't works user account but works with admin account Rupert Windows Software 2 20-02-2009 11:01 PM


All times are GMT +5.5. The time now is 03:55 AM.