100
100
import com .oracle .graal .python .builtins .modules .PosixModuleBuiltinsFactory .ConvertPathlikeObjectNodeGen ;
101
101
import com .oracle .graal .python .builtins .modules .PosixModuleBuiltinsFactory .StatNodeFactory ;
102
102
import com .oracle .graal .python .builtins .objects .PNone ;
103
+ import com .oracle .graal .python .builtins .objects .bytes .BytesNodes ;
103
104
import com .oracle .graal .python .builtins .objects .bytes .BytesNodes .ToBytesNode ;
104
105
import com .oracle .graal .python .builtins .objects .bytes .PByteArray ;
105
106
import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
@@ -288,34 +289,36 @@ public void postInitialize(PythonCore core) {
288
289
((PDict ) environAttr ).setDictStorage (environ .getDictStorage ());
289
290
}
290
291
291
- @ Builtin (name = "execv" , minNumOfPositionalArgs = 2 )
292
+ @ Builtin (name = "execv" , minNumOfPositionalArgs = 3 , declaresExplicitSelf = true )
292
293
@ GenerateNodeFactory
293
294
public abstract static class ExecvNode extends PythonBuiltinNode {
294
295
296
+ @ Child private BytesNodes .ToBytesNode toBytes = BytesNodes .ToBytesNode .create ();
297
+
295
298
@ Specialization
296
- Object execute (String path , PList args ) {
297
- return doExecute (path , args );
299
+ Object execute (PythonModule thisModule , String path , PList args ) {
300
+ return doExecute (thisModule , path , args );
298
301
}
299
302
300
303
@ Specialization
301
- Object execute (PString path , PTuple args ) {
302
- return execute (path .getValue (), args );
304
+ Object execute (PythonModule thisModule , PString path , PTuple args ) {
305
+ return execute (thisModule , path .getValue (), args );
303
306
}
304
307
305
308
@ Specialization
306
- Object execute (String path , PTuple args ) {
309
+ Object execute (PythonModule thisModule , String path , PTuple args ) {
307
310
// in case of execl the PList happens to be in the tuples first entry
308
311
Object list = GetItemDynamicNode .getUncached ().execute (args .getSequenceStorage (), 0 );
309
- return doExecute (path , list instanceof PList ? (PList ) list : args );
312
+ return doExecute (thisModule , path , list instanceof PList ? (PList ) list : args );
310
313
}
311
314
312
315
@ Specialization
313
- Object execute (PString path , PList args ) {
314
- return doExecute (path .getValue (), args );
316
+ Object execute (PythonModule thisModule , PString path , PList args ) {
317
+ return doExecute (thisModule , path .getValue (), args );
315
318
}
316
319
317
320
@ TruffleBoundary
318
- Object doExecute (String path , PSequence args ) {
321
+ Object doExecute (PythonModule thisModule , String path , PSequence args ) {
319
322
try {
320
323
if (!getContext ().isExecutableAccessAllowed ()) {
321
324
throw raise (OSError , "executable access denied" );
@@ -328,22 +331,25 @@ Object doExecute(String path, PSequence args) {
328
331
for (int i = 0 ; i < size ; i ++) {
329
332
cmd [i ] = GetItemDynamicNode .getUncached ().execute (args .getSequenceStorage (), i ).toString ();
330
333
}
331
- Runtime rt = Runtime .getRuntime ();
332
- Process pr = rt .exec (cmd );
334
+ PDict environ = (PDict ) thisModule .getAttribute ("environ" );
335
+ ProcessBuilder builder = new ProcessBuilder (cmd );
336
+ Map <String , String > environment = builder .environment ();
337
+ environ .entries ().forEach (entry -> {
338
+ environment .put (new String (toBytes .execute (null , (PBytes ) entry .key )), new String (toBytes .execute (null , (PBytes ) entry .value )));
339
+ });
340
+ Process pr = builder .start ();
333
341
// retrieve output from executed script
334
342
BufferedReader bfr = new BufferedReader (new InputStreamReader (pr .getInputStream ()));
335
343
OutputStream stream = getContext ().getEnv ().out ();
336
344
String line = "" ;
337
345
while ((line = bfr .readLine ()) != null ) {
338
346
stream .write (line .getBytes ());
339
347
}
340
-
341
348
try {
342
349
pr .waitFor ();
343
350
} catch (InterruptedException e ) {
344
351
throw new IOException (e );
345
352
}
346
-
347
353
throw new PythonExitException (this , pr .exitValue ());
348
354
} catch (IOException e ) {
349
355
throw raise (PythonErrorType .ValueError , "Could not execute script '%s'" , e .getMessage ());
@@ -362,7 +368,6 @@ String cwd() {
362
368
return "" ;
363
369
}
364
370
}
365
-
366
371
}
367
372
368
373
@ Builtin (name = "chdir" , minNumOfPositionalArgs = 1 )
0 commit comments