|
66 | 66 |
|
67 | 67 | public class GraalPythonMain extends AbstractLanguageLauncher {
|
68 | 68 |
|
| 69 | + private static final boolean IS_WINDOWS = System.getProperty("os.name") != null && System.getProperty("os.name").toLowerCase().contains("windows"); |
| 70 | + |
69 | 71 | private static final String SHORT_HELP = "usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...\n" +
|
70 | 72 | "Try `python -h' for more information.";
|
71 | 73 |
|
@@ -552,6 +554,25 @@ private String calculateProgramFullPath(String program, Function<Path, Boolean>
|
552 | 554 | return resolvedProgramName.toString();
|
553 | 555 | }
|
554 | 556 |
|
| 557 | + // On windows, the program name may be without the extension |
| 558 | + if (IS_WINDOWS) { |
| 559 | + String pathExtEnvvar = getEnv("PATHEXT"); |
| 560 | + if (pathExtEnvvar != null) { |
| 561 | + // default extensions are defined |
| 562 | + String resolvedStr = resolvedProgramName.toString(); |
| 563 | + if (resolvedStr.length() <= 3 || resolvedStr.charAt(resolvedStr.length() - 4) != '.') { |
| 564 | + // program has no file extension |
| 565 | + String[] pathExts = pathExtEnvvar.toLowerCase().split(";"); |
| 566 | + for (String pathExt : pathExts) { |
| 567 | + resolvedProgramName = Path.of(resolvedStr + pathExt); |
| 568 | + if (isExecutable.apply(resolvedProgramName)) { |
| 569 | + return resolvedProgramName.toString(); |
| 570 | + } |
| 571 | + } |
| 572 | + } |
| 573 | + } |
| 574 | + } |
| 575 | + |
555 | 576 | // next start is the char after the separator because we have "path0:path1" and
|
556 | 577 | // 'i' points to ':'
|
557 | 578 | previous = i + 1;
|
@@ -768,8 +789,7 @@ protected void launch(Builder contextBuilder) {
|
768 | 789 | contextBuilder.option("python.PyCachePrefix", cachePrefix);
|
769 | 790 | }
|
770 | 791 |
|
771 |
| - String osName = System.getProperty("os.name"); |
772 |
| - if (osName != null && osName.toLowerCase().contains("windows")) { |
| 792 | + if (IS_WINDOWS) { |
773 | 793 | contextBuilder.option("python.PosixModuleBackend", "java");
|
774 | 794 | }
|
775 | 795 |
|
|
0 commit comments