-
-
Notifications
You must be signed in to change notification settings - Fork 7k
/
Copy pathProcessUtils.java
28 lines (23 loc) · 964 Bytes
/
ProcessUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package processing.app.helpers;
import java.io.IOException;
import java.util.Map;
public class ProcessUtils {
public static Process exec(String[] command) throws IOException {
// No problems on linux and mac
if (!OSUtils.isWindows()) {
return Runtime.getRuntime().exec(command);
}
// Brutal hack to workaround windows command line parsing.
// http://stackoverflow.com/questions/5969724/java-runtime-exec-fails-to-escape-characters-properly
// http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
// http://bugs.sun.com/view_bug.do?bug_id=6468220
// http://bugs.sun.com/view_bug.do?bug_id=6518827
String[] cmdLine = new String[command.length];
for (int i = 0; i < command.length; i++)
cmdLine[i] = command[i].replace("\"", "\\\"");
ProcessBuilder pb = new ProcessBuilder(cmdLine);
Map<String, String> env = pb.environment();
env.put("CYGWIN", "nodosfilewarning");
return pb.start();
}
}