4040 */
4141package com .oracle .graal .python .builtins .modules ;
4242
43- import java .io .File ;
4443import java .io .IOException ;
45- import java .lang .ProcessBuilder .Redirect ;
4644import java .nio .ByteBuffer ;
4745import java .nio .channels .Channel ;
4846import java .nio .channels .WritableByteChannel ;
8684import com .oracle .truffle .api .dsl .Specialization ;
8785import com .oracle .truffle .api .frame .VirtualFrame ;
8886import com .oracle .truffle .api .interop .UnsupportedMessageException ;
87+ import com .oracle .truffle .api .io .TruffleProcessBuilder ;
8988import com .oracle .truffle .api .library .CachedLibrary ;
89+ import org .graalvm .polyglot .io .ProcessHandler .Redirect ;
9090
9191@ CoreFunctions (defineModule = "_posixsubprocess" )
9292public class PosixSubprocessModuleBuiltins extends PythonBuiltins {
@@ -142,11 +142,9 @@ private synchronized int forkExec(PList args, PList execList, @SuppressWarnings(
142142 }
143143 }
144144
145- File cwdFile ;
146145 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 ()) {
150148 throw raise (PythonBuiltinClassType .OSError , ErrorMessages .WORK_DIR_NOT_ACCESSIBLE , cwd );
151149 }
152150
@@ -232,11 +230,11 @@ private synchronized int forkExec(PList args, PList execList, @SuppressWarnings(
232230
233231 // Tries executing given arguments, throws IOException if the executable cannot be executed,
234232 // 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 ,
236234 int p2cwrite , int p2cread , int c2pwrite , int c2pread ,
237235 int errwrite , int errpipe_write , PosixResources resources , int errread ) throws IOException {
238236 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 ()]) );
240238 if (p2cread != -1 && p2cwrite != -1 ) {
241239 pb .redirectInput (Redirect .PIPE );
242240 } else {
@@ -260,7 +258,7 @@ private int exec(ArrayList<String> argStrings, File cwd, Map<String, String> env
260258 }
261259
262260 pb .directory (cwd );
263- pb .environment (). putAll ( env );
261+ pb .environment (env );
264262
265263 ProcessWrapper process = new ProcessWrapper (pb .start (), p2cwrite != -1 , c2pread != 1 , errread != -1 );
266264 try {
0 commit comments