RunAppAction.java

00001 package edu.stanford.hci.r3.actions.types;
00002 
00003 import java.io.File;
00004 import java.io.IOException;
00005 import java.util.Map;
00006 
00007 import edu.stanford.hci.r3.actions.R3Action;
00008 
00020 public class RunAppAction implements R3Action {
00021 
00022         private String executablePath;
00023 
00027         public RunAppAction(File execFile) {
00028                 executablePath = execFile.getPath();
00029         }
00030 
00036         public RunAppAction(String execName) {
00037                 executablePath = execName;
00038         }
00039 
00043         public void invoke() {
00044                 try {
00045                         File f = new File(executablePath);
00046                         String command = null;
00047                         if (!f.exists()) {
00048                                 // this probably means it is in the path, instead of in the local directory
00049                                 command = f.getName();
00050                         } else {
00051                                 // run this file!
00052                                 command = f.getAbsolutePath();
00053                         }
00054 
00055                         ProcessBuilder builder = new ProcessBuilder(command);
00056                         Map<String, String> env = builder.environment();
00057                         final String envPath = env.get("PATH");
00058                         String append = null;
00059                         if (envPath == null) {
00060                                 append = "";
00061                         } else {
00062                                 append = System.getProperty("path.separator") + envPath;
00063                         }
00064                         env.put("PATH", System.getProperty("java.library.path") + append);
00065                         builder.start();
00066                 } catch (IOException e) {
00067                         e.printStackTrace();
00068                 }
00069         }
00070 }

Generated on Sat Apr 14 18:21:38 2007 for R3 Paper Toolkit by  doxygen 1.4.7