The problem is that you read a multi-line
output
while (true) {
String line = inn.readLine();
if (line == null) {
break;
}
...
but you store always only the line which was current read in the textfield. Means previous output is overwritten.
...
motherboard.setText(line);
}
As the last line of the output is an empty line
your text field shows this empty line (means you don't see any output).
edit Below is added only for completeness.
A small method which could be used as String serialNumber = getSerialNumber()
. It filter out the header line and the empty lines.
static String getSerialNumber() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("wmic", "baseboard",
"get", "serialnumber");
Process process = pb.start();
process.waitFor();
String serialNumber = "";
try (BufferedReader br = new BufferedReader(new InputStreamReader(
process.getInputStream()))) {
for (String line = br.readLine(); line != null; line = br.readLine()) {
if (line.length() < 1 || line.startsWith("SerialNumber")) {
continue;
}
serialNumber = line;
break;
}
}
return serialNumber;
}
Another way could be to do the filtering already on the wmic
command and read only the first line from the output.
Either with commandlline tools provided by Windows
wmic baseboard get serialnumber | findstr /r /v "^$" | findstr /v "SerialNumber"
or using a custom XSL
to control the output of wmic
.
Save it as simple.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/"><xsl:apply-templates select="COMMAND/RESULTS"/>
</xsl:template>
</xsl:stylesheet>
and run the command as
wmic baseboard get serialnumber /Format:.\simple