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); } } }
protected void doSysValidation() { int nComps = m_pnlDisplay.getComponentCount(); JTextArea txaMsg = null; for (int i = 0; i < nComps; i++) { Component comp = m_pnlDisplay.getComponent(i); if (comp instanceof JTextArea) txaMsg = (JTextArea) comp; } if (txaMsg != null) { txaMsg.append("VALIDATING SYSTEM FILES...\n"); txaMsg.append("\n"); } runScripts(txaMsg); }
/** * Builds the components from the file and displays it. * * @param strFile the file to be read. */ public void build(int nType, String strFile, String strhelpfile) { m_nType = nType; m_strPath = (strFile != null) ? FileUtil.openPath(strFile) : ""; m_strHelpFile = strhelpfile; boolean bValidate = false; boolean bChecksum = false; if (nType == CONFIG) { setTitle("Configuration"); buildConfig(); } else { JComponent compDisplay = null; if (nType == DEFAULT) { m_pnlAccPolicy = new AccPolicyPanel(m_strPath); compDisplay = m_pnlAccPolicy; setTitle("Password Configuration"); } else if (nType == CHECKSUM) { m_pnlChecksum = new ChecksumPanel(m_strPath); compDisplay = m_pnlChecksum; setTitle("Checksum Configuration"); bValidate = true; bChecksum = true; } else { setTitle("Perform System Validation"); compDisplay = new JTextArea(); ((JTextArea) compDisplay).setEditable(false); bValidate = true; doBlink(); } m_pnlDisplay.removeAll(); m_pnlDisplay.setLayout(new BorderLayout()); m_pnlDisplay.add(compDisplay, BorderLayout.CENTER); setVisible(true); } validateButton.setVisible(bValidate); // abandonButton.setVisible(!bValidate); setAbandonEnabled(bValidate); m_btnChecksum.setVisible(bChecksum); }