Exemple #1
2
  protected void runScript(String[] cmd, JTextArea txaMsg) {
    String strg = "";

    if (cmd == null) return;

    Process prcs = null;
    try {
      Messages.postDebug("Running script: " + cmd[2]);
      Runtime rt = Runtime.getRuntime();

      prcs = rt.exec(cmd);

      if (prcs == null) return;

      InputStream istrm = prcs.getInputStream();
      if (istrm == null) return;

      BufferedReader bfr = new BufferedReader(new InputStreamReader(istrm));

      while ((strg = bfr.readLine()) != null) {
        // System.out.println(strg);
        strg = strg.trim();
        // Messages.postDebug(strg);
        strg = strg.toLowerCase();
        if (txaMsg != null) {
          txaMsg.append(strg);
          txaMsg.append("\n");
        }
      }
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
      Messages.postDebug(e.toString());
    } finally {
      // It is my understanding that these streams are left
      // open sometimes depending on the garbage collector.
      // So, close them.
      try {
        if (prcs != null) {
          OutputStream os = prcs.getOutputStream();
          if (os != null) os.close();
          InputStream is = prcs.getInputStream();
          if (is != null) is.close();
          is = prcs.getErrorStream();
          if (is != null) is.close();
        }
      } catch (Exception ex) {
        Messages.writeStackTrace(ex);
      }
    }
  }
    // Creates a new thread, runs the program in that thread, and reports any errors as needed.
    private void run(String clazz) {
      try {
        // Makes sure the JVM resets if it's already running.
        if (JVMrunning) kill();

        // Some String constants for java path and OS-specific separators.
        String separator = System.getProperty("file.separator");
        String path = System.getProperty("java.home") + separator + "bin" + separator + "java";

        // Tries to run compiled code.
        ProcessBuilder builder = new ProcessBuilder(path, clazz);

        // Should be good now! Everything past this is on you. Don't mess it up.
        println(
            "Build succeeded on " + java.util.Calendar.getInstance().getTime().toString(), progErr);
        println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", progErr);

        JVM = builder.start();

        // Note that as of right now, there is no support for input. Only output.
        Reader errorReader = new InputStreamReader(JVM.getErrorStream());
        Reader outReader = new InputStreamReader(JVM.getInputStream());
        // Writer inReader = new OutputStreamWriter(JVM.getOutputStream());

        redirectErr = redirectIOStream(errorReader, err);
        redirectOut = redirectIOStream(outReader, out);
        // redirectIn = redirectIOStream(null, inReader);
      } catch (Exception e) {
        // This catches any other errors we might get.
        println("Some error thrown", progErr);
        logError(e.toString());
        displayLog();
        return;
      }
    }
 public void run() {
   try {
     clientProcess.waitFor();
   } catch (InterruptedException ie) {
   }
   parent.remove(client);
 }
Exemple #4
0
 void doExitCommand() {
   File fp = new File(dataFile);
   boolean delete = fp.delete();
   pid.destroy();
   doResetCommand();
   setVisible(false);
 }
Exemple #5
0
  void doExeCommand() {
    PSlider slider;
    Runtime program = Runtime.getRuntime();
    String currentCmd = new String();
    String X = new String();
    String Y = new String();

    // Kill the current executing program
    pid.destroy();

    // Setup the command parameters and run it
    slider = (PSlider) vSlider.elementAt(0);
    X = slider.getValue();
    slider = (PSlider) vSlider.elementAt(1);
    Y = slider.getValue();
    currentCmd = cmd + " " + X + " " + Y;

    try {
      pid = program.exec(currentCmd);
      if (isWindows == false) {
        Process pid2 = null;
        pid2 = program.exec("getpid WinSize");
      }
    } catch (IOException ie) {
      System.err.println("Couldn't run " + ie);
      System.exit(-1);
    }

    // Update the new value in the source code of the program
    doSourceFileUpdate();
    scrollPane.getViewport().setViewPosition(new Point(0, 20));
  }
 public boolean continueShellProcess(Process proc) {
   if (progIndicator.isAborted()) {
     try {
       Writer stream;
       stream = new OutputStreamWriter((BufferedOutputStream) proc.getOutputStream());
       stream.write((char) 3);
       stream.flush();
       stream.close();
     } catch (IOException e) {
     }
     return false;
   }
   return true;
 }
    // Kills the JVM process and any active threads on it.
    private void kill() {
      if (redirectErr != null) {
        redirectErr.close();
        redirectErr.interrupt();
      }

      if (redirectOut != null) {
        redirectOut.close();
        redirectOut.interrupt();
      }

      if (JVM != null) {
        JVM.destroy();
        JVM = null;
      }

      JVMrunning = false;
    }
    // Kills the JVM process and any active threads on it.
    private void kill() {
      if (redirectErr != null) {
        redirectErr.close();
        redirectErr.interrupt();
      }

      if (redirectOut != null) {
        redirectOut.close();
        redirectOut.interrupt();
      }

      if (JVM != null) {
        JVM.destroy();
        JVM = null;
      }

      JVMrunning = false;

      println("JVM reset on " + java.util.Calendar.getInstance().getTime().toString(), progErr);
    }
Exemple #9
0
  // Run selected test cases.
  private void runTests() {

    for (int i = 0; i < tests.size(); i++) {
      // If box for test is checked, run it.
      if (tests.get(i).isSelected()) {

        // Get the URLs of all of the required files.
        String folderURL = tests.get(i).getText();
        String testURL = folderURL.concat(folderURL.substring(folderURL.lastIndexOf('/')));
        String efgFile = testURL + ".EFG";
        String guiFile = testURL + ".GUI";
        String tstFile = testURL + ".TST";
        String prgFile = testURL + ".PRG";

        // attempt to read in file with program's parameters
        try {
          FileInputStream fstream = new FileInputStream(prgFile);
          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          HashMap<String, String> prgParams = new HashMap<String, String>();
          String strLine;
          while ((strLine = br.readLine()) != null) {
            // add found parameters into prgParams as <key, value>
            String[] matches = strLine.split("=");
            prgParams.put(matches[0], matches[1]);
          }

          if (prgParams.containsKey("path") && prgParams.containsKey("main")) {
            programPath = prgParams.get("path");
            mainClass = prgParams.get("main");
          }

          in.close();
        } catch (Exception e) {
          System.err.println(e.getMessage());
        }

        System.out.println("We hit Run");

        // Run the replayer using the three test files.
        System.out.println(
            "../../../dist/guitar/jfc-replayer.sh -cp "
                + programPath
                + " -c "
                + mainClass
                + " -g "
                + guiFile
                + " -e "
                + efgFile
                + " -t "
                + tstFile);
        try {
          Runtime rt = Runtime.getRuntime();
          Process proc =
              rt.exec(
                  "../../../dist/guitar/jfc-replayer.sh -cp "
                      + programPath
                      + " -c "
                      + mainClass
                      + " -g "
                      + guiFile
                      + " -e "
                      + efgFile
                      + " -t "
                      + tstFile);

          // InputStream ips = proc.getInputStream();
          BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
          String inputLine;
          while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
          in.close();

        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
Exemple #10
0
 void doExitCommand() {
   // File fp = new File("link");
   // boolean delete = fp.delete();
   pid.destroy();
   setVisible(false);
 }
Exemple #11
0
 void doExitCommand() {
   pid.destroy();
   setVisible(false);
 }