@@ -54,6 +54,7 @@ public static Executor of(String... cmdline) {
5454 public Executor () {
5555 saveOutputType = new HashSet <>(Set .of (SaveOutputType .NONE ));
5656 removePathEnvVar = false ;
57+ winEnglishOutput = false ;
5758 }
5859
5960 public Executor setExecutable (String v ) {
@@ -90,6 +91,15 @@ public Executor setRemovePathEnvVar(boolean value) {
9091 return this ;
9192 }
9293
94+ public Executor setWinRunWithEnglishOutput (boolean value ) {
95+ if (!TKit .isWindows ()) {
96+ throw new UnsupportedOperationException (
97+ "setWinRunWithEnglishOutput is only valid on Windows platform" );
98+ }
99+ winEnglishOutput = value ;
100+ return this ;
101+ }
102+
93103 public Executor setWindowsTmpDir (String tmp ) {
94104 if (!TKit .isWindows ()) {
95105 throw new UnsupportedOperationException (
@@ -207,6 +217,11 @@ public Result executeWithoutExitCodeCheck() {
207217 "Can't change directory when using tool provider" );
208218 }
209219
220+ if (toolProvider != null && winEnglishOutput ) {
221+ throw new IllegalArgumentException (
222+ "Can't change locale when using tool provider" );
223+ }
224+
210225 return ThrowingSupplier .toSupplier (() -> {
211226 if (toolProvider != null ) {
212227 return runToolProvider ();
@@ -324,8 +339,17 @@ private Path executablePath() {
324339 return executable .toAbsolutePath ();
325340 }
326341
342+ private List <String > prefixCommandLineArgs () {
343+ if (winEnglishOutput ) {
344+ return List .of ("cmd.exe" , "/c" , "chcp" , "437" , ">nul" , "2>&1" , "&&" );
345+ } else {
346+ return List .of ();
347+ }
348+ }
349+
327350 private Result runExecutable () throws IOException , InterruptedException {
328351 List <String > command = new ArrayList <>();
352+ command .addAll (prefixCommandLineArgs ());
329353 command .add (executablePath ().toString ());
330354 command .addAll (args );
331355 ProcessBuilder builder = new ProcessBuilder (command );
@@ -457,15 +481,17 @@ public String getPrintableCommandLine() {
457481 exec = executablePath ().toString ();
458482 }
459483
460- return String .format (format , printCommandLine (exec , args ),
461- args .size () + 1 );
484+ var cmdline = Stream .of (prefixCommandLineArgs (), List .of (exec ), args ).flatMap (
485+ List ::stream ).toList ();
486+
487+ return String .format (format , printCommandLine (cmdline ), cmdline .size ());
462488 }
463489
464- private static String printCommandLine (String executable , List <String > args ) {
490+ private static String printCommandLine (List <String > cmdline ) {
465491 // Want command line printed in a way it can be easily copy/pasted
466- // to be executed manally
492+ // to be executed manually
467493 Pattern regex = Pattern .compile ("\\ s" );
468- return Stream . concat ( Stream . of ( executable ), args . stream () ).map (
494+ return cmdline . stream ().map (
469495 v -> (v .isEmpty () || regex .matcher (v ).find ()) ? "\" " + v + "\" " : v ).collect (
470496 Collectors .joining (" " ));
471497 }
@@ -479,6 +505,7 @@ private static void trace(String msg) {
479505 private Set <SaveOutputType > saveOutputType ;
480506 private Path directory ;
481507 private boolean removePathEnvVar ;
508+ private boolean winEnglishOutput ;
482509 private String winTmpDir = null ;
483510
484511 private static enum SaveOutputType {
0 commit comments