@@ -66,6 +66,9 @@ public static void main(String[] args) {
66
66
private static final String LANGUAGE_ID = "python" ;
67
67
private static final String MIME_TYPE = "text/x-python" ;
68
68
69
+ // provided by GraalVM bash launchers, ignored in native image mode
70
+ private static final String BASH_LAUNCHER_EXEC_NAME = System .getProperty ("org.graalvm.launcher.executablename" );
71
+
69
72
private ArrayList <String > programArgs = null ;
70
73
private String commandString = null ;
71
74
private String inputFile = null ;
@@ -287,6 +290,17 @@ private void addRelaunchArg(String arg) {
287
290
relaunchArgs .add (arg );
288
291
}
289
292
293
+ private String [] execListWithRelaunchArgs (String executableName ) {
294
+ if (relaunchArgs == null ) {
295
+ return new String []{executableName };
296
+ } else {
297
+ ArrayList <String > execList = new ArrayList <>(relaunchArgs .size () + 1 );
298
+ execList .add (executableName );
299
+ execList .addAll (relaunchArgs );
300
+ return execList .toArray (new String [execList .size ()]);
301
+ }
302
+ }
303
+
290
304
private static void printShortHelp () {
291
305
print ("usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...\n " +
292
306
"Try `python -h' for more information." );
@@ -298,13 +312,11 @@ private static void print(String string) {
298
312
299
313
private String [] getExecutableList () {
300
314
if (ImageInfo .inImageCode ()) {
301
- ArrayList <String > exec_list = new ArrayList <>();
302
- exec_list .add (ProcessProperties .getExecutableName ());
303
- if (relaunchArgs != null ) {
304
- exec_list .addAll (relaunchArgs );
305
- }
306
- return exec_list .toArray (new String [exec_list .size ()]);
315
+ return execListWithRelaunchArgs (ProcessProperties .getExecutableName ());
307
316
} else {
317
+ if (BASH_LAUNCHER_EXEC_NAME != null ) {
318
+ return execListWithRelaunchArgs (BASH_LAUNCHER_EXEC_NAME );
319
+ }
308
320
StringBuilder sb = new StringBuilder ();
309
321
ArrayList <String > exec_list = new ArrayList <>();
310
322
sb .append (System .getProperty ("java.home" )).append (File .separator ).append ("bin" ).append (File .separator ).append ("java" );
@@ -338,6 +350,9 @@ private String getExecutable() {
338
350
if (ImageInfo .inImageBuildtimeCode ()) {
339
351
return "" ;
340
352
} else {
353
+ if (BASH_LAUNCHER_EXEC_NAME != null ) {
354
+ return BASH_LAUNCHER_EXEC_NAME ;
355
+ }
341
356
String [] executableList = getExecutableList ();
342
357
for (int i = 0 ; i < executableList .length ; i ++) {
343
358
if (executableList [i ].matches ("\\ s" )) {
0 commit comments