If you want to use Java Runtime.exec() to run the WMIC command, please remember that : 1, you must write your command as "CMD /c WMIC ..." format. WMIC cannot work correctly if been invoked directly.
2, Do not forget to add "<NUL" at the end of command, otherwise your process never return sometimes.
I found the reason why Java programmers should add "<NUL" in the end of Command String. It is : "<NUL" will force the process to close its outputStream (for WMIC, what will be closed is its inputstream).
So you have an alternative: to explicitly run the this command ("process.getOutputStream().close()") after you redirect the inputstream to your own logs.
If you want to use Java Runtime.exec() to run the WMIC command, please remember that :
回复删除1, you must write your command as "CMD /c WMIC ..." format. WMIC cannot work correctly if been invoked directly.
2, Do not forget to add "<NUL" at the end of command, otherwise your process never return sometimes.
I found the reason why Java programmers should add "<NUL" in the end of Command String. It is : "<NUL" will force the process to close its outputStream (for WMIC, what will be closed is its inputstream).
回复删除So you have an alternative: to explicitly run the this command ("process.getOutputStream().close()") after you redirect the inputstream to your own logs.