B4J Question jShell - force reading stdOut inputStream

Discussion in 'B4J Questions' started by Daestrum, Feb 6, 2019.

  1. Daestrum

    Daestrum Well-Known Member Licensed User

    Is there a way to force the sh_stdOut to re-read the inputStream in case bytes have arrived since the last read.

    If I use Process I can use this construct to ensure I get all the data.
    Code:
    Sub outputToCons
     
    Dim buf(consOut.BytesAvailable) As Byte
     
    If consOut.BytesAvailable > 0 Then
      consOut.ReadBytes(buf,
    0,consOut.BytesAvailable)
      
    Dim st As String = BytesToString(buf,0,buf.Length,"utf8")
      TextArea1.text = TextArea1.text & st
      TextArea1.SelectAll
      TextArea1.SetSelection(TextArea1.SelectionEnd,TextArea1.SelectionEnd)
     
    End If
     Sleep(
    20)
     
    If consOut.BytesAvailable>0 Then outputToCons
    End Sub
    Just wondered if there was a method within jshell I could use to do the same.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Not sure that I understand. All the data will be available through the StdOut event. You can use StringBuilder or BytesBuilder to collect the data and work with it whenever you like.
     
  3. Daestrum

    Daestrum Well-Known Member Licensed User

    I will try and explain.

    (trying jshell and directly coding a Process)

    I am trying to get the output from a persistent command prompt window (started with /k).
    The first data returned from it is ok, the headers for the shell.
    But subsequent data returned on _stdOut in response to WriteToInputStream(…) is patchy, I may get the top part or the last few lines, but never the complete response unless it's really short.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Where does consOut come from?

    Start with:
    Code:
    Sub shl_StdOut(StdOut (Buffer() As Byte, Length As Int)
     
    Log(BytesToString(Buffer, 0, Length, "utf8"))
    End Sub
    It should print the full logs.

    Note that StdOut / StdErr events are raised on a different thread.
     
  5. Daestrum

    Daestrum Well-Known Member Licensed User

    consOut is the stream from p.getInputStream() ( the process inputstream from the processbuilder)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice