3434 * @run testng/othervm/native TestAvailableProcessors
3535 */
3636
37+ import java .io .File ;
3738import java .io .IOException ;
3839import java .util .List ;
3940import java .util .HashSet ;
@@ -58,7 +59,23 @@ public class TestAvailableProcessors {
5859 private static String getWindowsVersion () throws IOException {
5960 String systeminfoPath = "systeminfo.exe" ;
6061
61- var processBuilder = new ProcessBuilder (systeminfoPath );
62+ List <String > command = new ArrayList <>();
63+
64+ String systemRoot = System .getenv ("SystemRoot" );
65+ if (systemRoot == null ) {
66+ systemRoot = System .getenv ("WINDIR" );
67+ if (systemRoot == null ) {
68+ throw new RuntimeException ("SystemRoot or WINDIR environment variable is not set." );
69+ }
70+ }
71+ String system32 = Path .of (systemRoot , "System32" ).toString ();
72+
73+ // It switches the active code page to cp437, the default code page for US english.
74+ command .addAll (List .of ("cmd.exe" , "/c" , "set" , "PATH=%PATH%;" + system32 + ";" + system32 + "\\ wbem" , "&&" ));
75+ command .addAll (List .of ("chcp" , "437" , ">nul" , "2>&1" , "&&" ));
76+ command .add (systeminfoPath );
77+
78+ var processBuilder = new ProcessBuilder (command );
6279 OutputAnalyzer outputAnalyzer = new OutputAnalyzer (processBuilder .start ());
6380 outputAnalyzer .shouldHaveExitValue (0 );
6481 outputAnalyzer .shouldContain (osVersionMessage );
0 commit comments