0

I am executing some commands using ProcessBuilder as follows:

BufferedReader response = null;
process = processBuilder.start();           
response = new BufferedReader(new InputStreamReader(process.getInputStream()));

But code blocks at following line, while read line from response.

while((line = response.readLine()) != null) {
  /* some code here */
}

I did some google and I found that when readLine() not get EOL then it will block.

How can I make it work or resolve that issue.

user207421
  • 305,947
  • 44
  • 307
  • 483
Sachin J
  • 2,081
  • 12
  • 36
  • 50

1 Answers1

1

According to the API, this is what is indicated for readLine()

Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

So i think you'll have to make sure you are providing line terminator to avoid blocking.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
tmwanik
  • 1,643
  • 14
  • 20
  • How do I set line terminator? The response is returned by executing process builder. Just I can read it. right? – Sachin J Mar 20 '13 at 21:10
  • line = response.readLine() I dont get any response or string at this line. So I am unable to append '\n' at the end of line. – Sachin J Mar 20 '13 at 21:16
  • @Addict comment should sort that out, read `bytes` instead of `lines` – tmwanik Mar 20 '13 at 21:27