40
40
*/
41
41
package com .oracle .graal .python .builtins .modules ;
42
42
43
- import java .io .File ;
44
43
import java .io .IOException ;
45
- import java .lang .ProcessBuilder .Redirect ;
46
44
import java .nio .ByteBuffer ;
47
45
import java .nio .channels .Channel ;
48
46
import java .nio .channels .WritableByteChannel ;
86
84
import com .oracle .truffle .api .dsl .Specialization ;
87
85
import com .oracle .truffle .api .frame .VirtualFrame ;
88
86
import com .oracle .truffle .api .interop .UnsupportedMessageException ;
87
+ import com .oracle .truffle .api .io .TruffleProcessBuilder ;
89
88
import com .oracle .truffle .api .library .CachedLibrary ;
89
+ import org .graalvm .polyglot .io .ProcessHandler .Redirect ;
90
90
91
91
@ CoreFunctions (defineModule = "_posixsubprocess" )
92
92
public class PosixSubprocessModuleBuiltins extends PythonBuiltins {
@@ -142,11 +142,9 @@ private synchronized int forkExec(PList args, PList execList, @SuppressWarnings(
142
142
}
143
143
}
144
144
145
- File cwdFile ;
146
145
Env truffleEnv = context .getEnv ();
147
- if (getSafeTruffleFile (truffleEnv , cwd ).exists ()) {
148
- cwdFile = new File (cwd );
149
- } else {
146
+ TruffleFile cwdFile = getSafeTruffleFile (truffleEnv , cwd );
147
+ if (!cwdFile .exists ()) {
150
148
throw raise (PythonBuiltinClassType .OSError , ErrorMessages .WORK_DIR_NOT_ACCESSIBLE , cwd );
151
149
}
152
150
@@ -232,11 +230,11 @@ private synchronized int forkExec(PList args, PList execList, @SuppressWarnings(
232
230
233
231
// Tries executing given arguments, throws IOException if the executable cannot be executed,
234
232
// any other error is handled here
235
- private int exec (ArrayList <String > argStrings , File cwd , Map <String , String > env ,
233
+ private int exec (ArrayList <String > argStrings , TruffleFile cwd , Map <String , String > env ,
236
234
int p2cwrite , int p2cread , int c2pwrite , int c2pread ,
237
235
int errwrite , int errpipe_write , PosixResources resources , int errread ) throws IOException {
238
236
LOGGER .finest (() -> "_posixsubprocess.fork_exec trying to exec: " + String .join (" " , argStrings ));
239
- ProcessBuilder pb = new ProcessBuilder ( argStrings );
237
+ TruffleProcessBuilder pb = getContext (). getEnv (). newProcessBuilder ( argStrings . toArray ( new String [ argStrings . size ()]) );
240
238
if (p2cread != -1 && p2cwrite != -1 ) {
241
239
pb .redirectInput (Redirect .PIPE );
242
240
} else {
@@ -260,7 +258,7 @@ private int exec(ArrayList<String> argStrings, File cwd, Map<String, String> env
260
258
}
261
259
262
260
pb .directory (cwd );
263
- pb .environment (). putAll ( env );
261
+ pb .environment (env );
264
262
265
263
ProcessWrapper process = new ProcessWrapper (pb .start (), p2cwrite != -1 , c2pread != 1 , errread != -1 );
266
264
try {
0 commit comments