@@ -53,6 +53,7 @@ public static Executor of(String... cmdline) {
5353 public Executor () {
5454 saveOutputType = new HashSet <>(Set .of (SaveOutputType .NONE ));
5555 removePath = false ;
56+ winEnglishOutput = false ;
5657 }
5758
5859 public Executor setExecutable (String v ) {
@@ -89,6 +90,15 @@ public Executor setRemovePath(boolean value) {
8990 return this ;
9091 }
9192
93+ public Executor setWinRunWithEnglishOutput (boolean value ) {
94+ if (!TKit .isWindows ()) {
95+ throw new UnsupportedOperationException (
96+ "setWinRunWithEnglishOutput is only valid on Windows platform" );
97+ }
98+ winEnglishOutput = value ;
99+ return this ;
100+ }
101+
92102 public Executor setWindowsTmpDir (String tmp ) {
93103 if (!TKit .isWindows ()) {
94104 throw new UnsupportedOperationException (
@@ -206,6 +216,11 @@ public Result executeWithoutExitCodeCheck() {
206216 "Can't change directory when using tool provider" );
207217 }
208218
219+ if (toolProvider != null && winEnglishOutput ) {
220+ throw new IllegalArgumentException (
221+ "Can't change locale when using tool provider" );
222+ }
223+
209224 return ThrowingSupplier .toSupplier (() -> {
210225 if (toolProvider != null ) {
211226 return runToolProvider ();
@@ -285,8 +300,17 @@ private Path executablePath() {
285300 return executable .toAbsolutePath ();
286301 }
287302
303+ private List <String > prefixCommandLineArgs () {
304+ if (winEnglishOutput ) {
305+ return List .of ("cmd.exe" , "/c" , "chcp" , "437" , ">nul" , "2>&1" , "&&" );
306+ } else {
307+ return List .of ();
308+ }
309+ }
310+
288311 private Result runExecutable () throws IOException , InterruptedException {
289312 List <String > command = new ArrayList <>();
313+ command .addAll (prefixCommandLineArgs ());
290314 command .add (executablePath ().toString ());
291315 command .addAll (args );
292316 ProcessBuilder builder = new ProcessBuilder (command );
@@ -418,15 +442,17 @@ public String getPrintableCommandLine() {
418442 exec = executablePath ().toString ();
419443 }
420444
421- return String .format (format , printCommandLine (exec , args ),
422- args .size () + 1 );
445+ var cmdline = Stream .of (prefixCommandLineArgs (), List .of (exec ), args ).flatMap (
446+ List ::stream ).toList ();
447+
448+ return String .format (format , printCommandLine (cmdline ), cmdline .size ());
423449 }
424450
425- private static String printCommandLine (String executable , List <String > args ) {
451+ private static String printCommandLine (List <String > cmdline ) {
426452 // Want command line printed in a way it can be easily copy/pasted
427- // to be executed manally
453+ // to be executed manually
428454 Pattern regex = Pattern .compile ("\\ s" );
429- return Stream . concat ( Stream . of ( executable ), args . stream () ).map (
455+ return cmdline . stream ().map (
430456 v -> (v .isEmpty () || regex .matcher (v ).find ()) ? "\" " + v + "\" " : v ).collect (
431457 Collectors .joining (" " ));
432458 }
@@ -440,6 +466,7 @@ private static void trace(String msg) {
440466 private Set <SaveOutputType > saveOutputType ;
441467 private Path directory ;
442468 private boolean removePath ;
469+ private boolean winEnglishOutput ;
443470 private String winTmpDir = null ;
444471
445472 private static enum SaveOutputType {
0 commit comments