| 5344 | } |
| 5345 | |
| 5346 | String exec() { |
| 5347 | String[] cmd; |
| 5348 | StringBuffer sb = new StringBuffer(256); |
| 5349 | String arg1 = getFirstString(); |
| 5350 | if (interp.nextToken()==',') { |
| 5351 | Vector v = new Vector(); |
| 5352 | v.add(arg1); |
| 5353 | do |
| 5354 | v.add(getNextString()); |
| 5355 | while (interp.nextToken()==','); |
| 5356 | cmd = new String[v.size()]; |
| 5357 | v.copyInto((String[])cmd); |
| 5358 | } else |
| 5359 | cmd = Tools.split(arg1); |
| 5360 | interp.getRightParen(); |
| 5361 | boolean openingDoc = cmd.length==2&&cmd[0].equals("open") || cmd.length==5&&cmd[3].equals("excel.exe"); |
| 5362 | if (openingDoc&&IJ.isWindows()) { |
| 5363 | String path = cmd[1]; |
| 5364 | if (path.startsWith("http://")||path.startsWith("HTTP://")) { |
| 5365 | cmd = new String[4]; |
| 5366 | cmd[2] = "start"; |
| 5367 | cmd[3] = path; |
| 5368 | } else { |
| 5369 | cmd = new String[3]; |
| 5370 | cmd[2] = path; |
| 5371 | } |
| 5372 | cmd[0] = "cmd"; |
| 5373 | cmd[1] = "/c"; |
| 5374 | } |
| 5375 | BufferedReader reader = null; |
| 5376 | try { |
| 5377 | Process p = Runtime.getRuntime().exec(cmd); |
| 5378 | boolean returnImmediately = openingDoc || !waitForCompletion; |
| 5379 | waitForCompletion = true; |
| 5380 | if (returnImmediately){ |
| 5381 | handleProcessBuffers(p.getInputStream(), p.getErrorStream()); // empty both buffers |
| 5382 | return null; |
| 5383 | } else { |
| 5384 | handleProcessBuffers(p.getErrorStream()); // empty only unused ErrorStream buffer |
| 5385 | } |
| 5386 | reader = new BufferedReader(new InputStreamReader(p.getInputStream())); // notice that this function will discard all process error output |
| 5387 | String line; int count=1; |
| 5388 | while ((line=reader.readLine())!=null) { |
| 5389 | sb.append(line+"\n"); |
| 5390 | if (count++==1&&line.startsWith("Microsoft Windows")){ |
| 5391 | handleProcessBuffers(p.getInputStream()); // must empty the InputStream buffer anyway |
| 5392 | break; // user probably ran 'cmd' without /c option |
| 5393 | } |
| 5394 | } |
| 5395 | } catch (Exception e) { |
| 5396 | sb.append(e.getMessage()+"\n"); |
| 5397 | } finally { |
| 5398 | if (reader!=null) try {reader.close();} catch (IOException e) {} |
| 5399 | } |
| 5400 | return sb.toString(); |
| 5401 | } |
| 5402 | |
| 5403 | double getValue() { |