Results 1 to 6 of 6

Thread: getOutputStream() works only once

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    getOutputStream() works only once

    Hello,
    I have the following code:
    Launches a cpp program.
    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.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: getOutputStream() works only once

    Hello
    See, if removing the buffering may help you. Something like this, here is the code.
    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.

  4. #4
    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.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  6. #6
    Join Date
    Dec 2009
    Posts
    296

    Re: getOutputStream() works only once

    Hello,
    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.
    There NYI if that is specifically made for this kind of problem.
    Really? It is part of the API by default?

Similar Threads

  1. How does VPN Works
    By Culpritism in forum Networking & Security
    Replies: 1
    Last Post: 03-12-2011, 04:18 PM
  2. Replies: 5
    Last Post: 26-08-2011, 10:31 PM
  3. How does JDK 5.0 works
    By Langward in forum Software Development
    Replies: 5
    Last Post: 14-02-2010, 05:00 AM
  4. Replies: 3
    Last Post: 19-08-2009, 07:21 PM
  5. Replies: 2
    Last Post: 21-02-2009, 12:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,659,260.53040 seconds with 17 queries