I'm running this in Java:
Runtime.getRuntime().exec("wmic bios get SerialNumber");
and when I read the output of that command, the line separator is not the expected \r\n
, but instead, \r\r\n
. The output of that command on cmd
looks like this:
C:\Users\pupeno>wmic bios get SerialNumber
SerialNumber
System Serial Number
C:\Users\pupeno>
If I read the output with a BufferedReader
:
System.out.println("====================");
BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = output.readLine()) != null) {
System.out.println(line);
}
System.out.println("====================");
it looks like this:
====================
SerialNumber
System Serial Number
====================
As you can see, I'm getting an extra blank line per line. Investigating it by reading it straight from the InputStreamReader
like this:
try (InputStreamReader inputStreamReader = new InputStreamReader(p.getInputStream())) {
int c;
while ((c = inputStreamReader.read()) != -1) {
String ch = String.valueOf((char) c);
switch(c) {
case 10:
ch = "LF";
break;
case 13:
ch = "CR";
break;
case 32:
ch = "Space";
break;
}
System.out.printf("%3d - %s%n", c, ch);
}
}
I get this output:
83 - S
101 - e
114 - r
105 - i
97 - a
108 - l
78 - N
117 - u
109 - m
98 - b
101 - e
114 - r
32 - Space
32 - Space
32 - Space
32 - Space
32 - Space
32 - Space
32 - Space
32 - Space
32 - Space
32 - Space
13 - CR
13 - CR
10 - LF
83 - S
121 - y
115 - s
116 - t
101 - e
109 - m
32 - Space
83 - S
101 - e
114 - r
105 - i
97 - a
108 - l
32 - Space
78 - N
117 - u
109 - m
98 - b
101 - e
114 - r
32 - Space
32 - Space
13 - CR
13 - CR
10 - LF
13 - CR
13 - CR
10 - LF
Any ideas why this is happening? Will all Windows computers behave like this?