Skip to content

Commit 94769c6

Browse files
committed
Use TrufflePocessBuilder instead of java.lang.ProcessBuilder
1 parent 162dd1d commit 94769c6

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixSubprocessModuleBuiltins.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules;
4242

43-
import java.io.File;
4443
import java.io.IOException;
45-
import java.lang.ProcessBuilder.Redirect;
4644
import java.nio.ByteBuffer;
4745
import java.nio.channels.Channel;
4846
import java.nio.channels.WritableByteChannel;
@@ -86,7 +84,9 @@
8684
import com.oracle.truffle.api.dsl.Specialization;
8785
import com.oracle.truffle.api.frame.VirtualFrame;
8886
import com.oracle.truffle.api.interop.UnsupportedMessageException;
87+
import com.oracle.truffle.api.io.TruffleProcessBuilder;
8988
import com.oracle.truffle.api.library.CachedLibrary;
89+
import org.graalvm.polyglot.io.ProcessHandler.Redirect;
9090

9191
@CoreFunctions(defineModule = "_posixsubprocess")
9292
public 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

Comments
 (0)