Skip to content

Commit f65e736

Browse files

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

app/src/processing/app/debug/Compiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import processing.app.Sketch;
4040
import processing.app.SketchCode;
4141
import processing.app.helpers.PreferencesMap;
42+
import processing.app.helpers.ProcessUtils;
4243
import processing.app.helpers.StringReplacer;
4344
import processing.app.helpers.filefilters.OnlyDirs;
4445
import processing.app.packages.Library;
@@ -343,9 +344,8 @@ private void execAsynchronously(String[] command) throws RunnerException {
343344
secondErrorFound = false;
344345

345346
Process process;
346-
347347
try {
348-
process = Runtime.getRuntime().exec(command);
348+
process = ProcessUtils.exec(command);
349349
} catch (IOException e) {
350350
RunnerException re = new RunnerException(e.getMessage());
351351
re.hideStackTrace();

app/src/processing/app/debug/Sizer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.regex.Pattern;
3131

3232
import processing.app.helpers.PreferencesMap;
33+
import processing.app.helpers.ProcessUtils;
3334
import processing.app.helpers.StringReplacer;
3435

3536
public class Sizer implements MessageConsumer {
@@ -67,7 +68,7 @@ public long[] computeSize() throws RunnerException {
6768
textSize = -1;
6869
dataSize = -1;
6970
eepromSize = -1;
70-
Process process = Runtime.getRuntime().exec(cmd);
71+
Process process = ProcessUtils.exec(cmd);
7172
MessageSiphon in = new MessageSiphon(process.getInputStream(), this);
7273
MessageSiphon err = new MessageSiphon(process.getErrorStream(), this);
7374

app/src/processing/app/debug/Uploader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import processing.app.Preferences;
3737
import processing.app.Serial;
3838
import processing.app.SerialNotFoundException;
39+
import processing.app.helpers.ProcessUtils;
3940

4041
public abstract class Uploader implements MessageConsumer {
4142
static final String BUGS_URL =
@@ -107,7 +108,7 @@ protected boolean executeUploadCommand(String commandArray[])
107108
}
108109
System.out.println();
109110
}
110-
Process process = Runtime.getRuntime().exec(commandArray);
111+
Process process = ProcessUtils.exec(commandArray);
111112
new MessageSiphon(process.getInputStream(), this);
112113
new MessageSiphon(process.getErrorStream(), this);
113114

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package processing.app.helpers;
2+
3+
import java.io.IOException;
4+
5+
import processing.app.Base;
6+
7+
public class ProcessUtils {
8+
9+
public static Process exec(String[] command) throws IOException {
10+
// No problems on linux and mac
11+
if (!Base.isWindows()) {
12+
return Runtime.getRuntime().exec(command);
13+
}
14+
15+
// Brutal hack to workaround windows command line parsing.
16+
// http://stackoverflow.com/questions/5969724/java-runtime-exec-fails-to-escape-characters-properly
17+
// http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
18+
// http://bugs.sun.com/view_bug.do?bug_id=6468220
19+
// http://bugs.sun.com/view_bug.do?bug_id=6518827
20+
String[] cmdLine = new String[command.length];
21+
for (int i = 0; i < command.length; i++)
22+
cmdLine[i] = command[i].replace("\"", "\\\"");
23+
return Runtime.getRuntime().exec(cmdLine);
24+
}
25+
}

0 commit comments

Comments
 (0)