File tree Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 3939import processing .app .Sketch ;
4040import processing .app .SketchCode ;
4141import processing .app .helpers .PreferencesMap ;
42+ import processing .app .helpers .ProcessUtils ;
4243import processing .app .helpers .StringReplacer ;
4344import processing .app .helpers .filefilters .OnlyDirs ;
4445import 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 ();
Original file line number Diff line number Diff line change 3030import java .util .regex .Pattern ;
3131
3232import processing .app .helpers .PreferencesMap ;
33+ import processing .app .helpers .ProcessUtils ;
3334import processing .app .helpers .StringReplacer ;
3435
3536public 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
Original file line number Diff line number Diff line change 3636import processing .app .Preferences ;
3737import processing .app .Serial ;
3838import processing .app .SerialNotFoundException ;
39+ import processing .app .helpers .ProcessUtils ;
3940
4041public 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments