Esempio n. 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);
      }
    }
  }
Esempio n. 2
0
  private void openNmrFile() {
    if (fileName.equals("text")) {
      try {
        Runtime.getRuntime().exec("notepad " + fullPath);
      } catch (Exception e) {
      }
    } else if (fileName.equals("fid")) {
      directory = UtilB.windowsPathToUnix(directory);
      if (directory.charAt(directory.length() - 1) == '/') {
        directory = directory.substring(0, directory.length() - 1);
      }
      Util.sendToVnmr("rt (\'" + directory + "\')");
      Util.sendToVnmr("write(\'line3\',\'fid retrieved\')");
    } else if (fileName.equals("procpar")) {
      directory = UtilB.windowsPathToUnix(directory);
      if (directory.charAt(directory.length() - 1) == '/') {
        directory = directory.substring(0, directory.length() - 1);
      }
      Util.sendToVnmr("rtp (\'" + directory + "\')");
      Util.sendToVnmr("write(\'line3\',\'parameters retrieved\')");
    } else {
      Util.sendToVnmr("write(\'error\',\'unknown file -- open ignored\')");
    }

    return;
  }