Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the message from process.getErrorStream()

Tags:

java

InputStream error = p.getErrorStream();
for (int i = 0; i < error.available(); i++) {
    err += error.read();
}
System.out.println(err);

It gives some numeric values. But, I need to get the error message, like e.getLocalizedMessage() whatever it will give.

like image 594
Suresh Palanisamy Avatar asked Oct 30 '22 17:10

Suresh Palanisamy


1 Answers

Java's InputStream.read() returns an integer value of a byte of data that is read, or (-1) if it is the end of the stream. I assume that your 'err' variable is a String, so adding an integer to a string adds the numeric value to it, therefore, you can cast error.read() to a (char) like this:

err += (char) error.read();
like image 114
MrPublic Avatar answered Nov 15 '22 04:11

MrPublic