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); } } }
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)); }
private void killUNIXProcess() { Runtime program = Runtime.getRuntime(); try { pid = program.exec("trigger WinSize"); } catch (IOException ie) { System.err.println("Error in killing process " + ie); System.exit(-1); } }
/** 帮助文档 */ private void help() { Runtime rt = Runtime.getRuntime(); try { logger.info("打开帮助文档. - " + TMFrame.class.getName()); rt.exec("hh.exe help.chm"); logger.info("打开帮助文档成功. - " + TMFrame.class.getName()); } catch (IOException e) { logger.error("打开帮助文档失败! - " + TMFrame.class.getName()); JOptionPane.showMessageDialog(this, "系统无法打开帮助文档,请联系开发人员。", "提示", JOptionPane.ERROR_MESSAGE); } }
void doExeCommand() { JViewport viewport = scrollPane.getViewport(); String strContent = new String(); PSlider slider; int i; File fp = new File(dataFile); RandomAccessFile access = null; Runtime program = Runtime.getRuntime(); String cmdTrigger = "trigger"; boolean delete = fp.delete(); try { fp.createNewFile(); } catch (IOException ie) { System.err.println("Couldn't create the new file " + ie); // System.exit(-1);; } try { access = new RandomAccessFile(fp, "rw"); } catch (IOException ie) { System.err.println("Error in accessing the file " + ie); // System.exit(-1);; } for (i = 0; i < COMPONENTS; i++) { slider = (PSlider) vSlider.elementAt(i); /* Modified on March 20th to satisfy advisors' new request */ if (slider.isString == true) strContent = strContent + slider.getRealStringValue() + " "; else strContent = strContent + slider.getValue() + " "; } // Get value of the radio button group if (firstBox.isSelected() == true) strContent = strContent + "1"; else strContent = strContent + "0"; try { access.writeBytes(strContent); access.close(); } catch (IOException ie) { System.err.println("Error in writing to file " + ie); // System.exit(-1);; } // Trigger the OpenGL program to update with new values try { Process pid = program.exec(cmdTrigger); } catch (IOException ie) { System.err.println("Couldn't run " + ie); // System.exit(-1);; } doSourceFileUpdate(); }
public static void showDesktop() { // Windows only try { if (SystemUtils.isWinPlatform()) RUNTIME.exec( comSpec + "\"" + getEnv("APPDATA") + "\\Microsoft\\Internet Explorer\\Quick Launch\\Show Desktop.scf\""); } catch (IOException e) { e.printStackTrace(); } }
private void printCurrent() { if (tableModel instanceof TransportTableModel) { Transport o = (Transport) tableModel.getRowData(objectTable.getSelectedRow()); String filename = TransportHelper.createHTMLFileFromTransport(o); try { Runtime runtime = Runtime.getRuntime(); runtime.exec("explorer " + filename); } catch (IOException ioe) { System.out.println(ioe); } } }
public static int ensureNTServiceIsRunning(String serviceName, String service) throws Exception { ArrayList<String> serviceList = getRunningNTServices(); if (serviceList == null) return -1; // not NT kernel? for (String svc : serviceList) { if (serviceName.equals(svc.trim())) return 0; // service already running } Process process = RUNTIME.exec(comSpec + "net start \"" + service + "\""); process.waitFor(); // wait for the process to complete int rc = process.exitValue(); // pick up its return code boolean success = (rc == 0); if (success) System.out.println("Successfully started service '" + serviceName + "'."); return (success ? 1 : -1); }
/** * Runs the given editor (the editor string is the command-line for the editor) for the particular * fileName. */ public static void showEditorFor(String editor, String filename) { try { Runtime runtime = Runtime.getRuntime(); String command = editor + " " + filename; runtime.exec(command); // execute it! } catch (Exception ee) { ErrorDialog.show( "Sorry, Error executing " + editor + "\nPlease, go to the Options menu in the MainTrianaWindow\n" + "and choose a valid editor for this file type."); } }
private boolean startLauncher(File dir) { try { Runtime rt = Runtime.getRuntime(); ArrayList<String> command = new ArrayList<String>(); command.add("java"); command.add("-jar"); command.add("Launcher.jar"); String[] cmdarray = command.toArray(new String[command.size()]); Process proc = rt.exec(cmdarray, null, dir); return true; } catch (Exception ex) { System.err.println("Unable to start the Launcher program.\n" + ex.getMessage()); return false; } }
/** Execute the system command 'cmd' and fill an ArrayList with the results. */ public static ArrayList<String> executeSystemCommand(String cmd) { if (debug) System.out.println("cmd: " + cmd); ArrayList<String> list = new ArrayList<>(); try (BufferedReader br = new BufferedReader( new InputStreamReader(RUNTIME.exec(/*comSpec +*/ cmd).getInputStream()))) { for (String line = null; (line = br.readLine()) != null; ) { if (debug) System.out.println(line); list.add(line); } } catch (IOException e) { e.printStackTrace(); } return list; }
public static String ping(String address) { String reply = "Request timed out"; try (BufferedReader br = new BufferedReader( new InputStreamReader(RUNTIME.exec("ping " + address).getInputStream()))) { for (String line = null; (line = br.readLine()) != null; ) { if (line.trim().startsWith("Reply ")) { reply = line; break; } } } catch (IOException e) { e.printStackTrace(); } return reply; }
public static Properties getEnvironmentVariables() { synchronized (cygstartPath) { if (envVars != null) return envVars; envVars = new Properties(); try (BufferedReader br = new BufferedReader( new InputStreamReader(RUNTIME.exec(comSpec + "env").getInputStream()))) { for (String line = null; (line = br.readLine()) != null; ) { // if (debug) System.out.println("getEnvironmentVariables(): line=" + line); int idx = line.indexOf('='); if (idx > 0) envVars.put(line.substring(0, idx), line.substring(idx + 1)); } } catch (IOException e) { e.printStackTrace(); } return envVars; } }
/** Display default email client to type and send an email. */ public static void sendMail() throws IOException { if (isWinPlatform()) RUNTIME.exec("rundll32 url.dll,FileProtocolHandler mailto:[email protected]?subject=Houdy"); }
public OrderTrans2() { super(windowTitle); int i; int currentPanel; // Value to specify which is the current panel in the vector JPanel subPanel = new JPanel(); // value used when adding sliders to the frame Runtime program = Runtime.getRuntime(); Container content = getContentPane(); createSliderVector(); createPanelVector(); getCodeSwapString(); /** Set code-swap strings' value. */ /** Get current OS of the system. */ if (System.getProperty("os.name").startsWith("Windows")) isWindows = true; else isWindows = false; /** Add the radio buttons to the group */ radioGrp.add(firstBox); radioGrp.add(secondBox); /** Set interactive buttons for the user interface */ JButton exeButton = new JButton("Execute"); exeButton.setToolTipText("Re-execute the program"); JButton resetButton = new JButton("Reset"); resetButton.setToolTipText("Reset Value"); JButton exitButton = new JButton("Exit"); exitButton.setToolTipText("Exit the Program"); // Create the main panel that contains everything. JPanel mainPanel = new JPanel(); // Create the panel that contains the sliders JPanel subPanel1 = new JPanel(); // Create the panel that contains the checkboxes JPanel subPanel2 = new JPanel(); // Create the panel that contains the buttons JPanel subPanel3 = new JPanel(); // JScrollPane scrollPane = new JScrollPane(); // main text pane with scroll bars content.add(mainPanel, BorderLayout.SOUTH); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); content.add(scrollPane, BorderLayout.CENTER); scrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); scrollPane.getViewport().add(textPane); mainPanel.add(subPanel1); mainPanel.add(subPanel2); mainPanel.add(subPanel3); subPanel1.setLayout(new GridLayout(0, 1)); /** Add subPanel elements to the subPanel1, each would be a row of sliders */ for (i = 0; i < ROWS; i++) subPanel1.add((JPanel) vSubPanel.elementAt(i)); /** Set the first element in the Panel Vector as the current subPanel. */ currentPanel = 0; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); /** Allocate sliders to the sub-panels. */ for (i = 0; i < COMPONENTS; i++) { PSlider slider = (PSlider) vSlider.elementAt(i); if (slider.getResideValue() == 'n') { currentPanel += 1; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); } subPanel.add((PSlider) vSlider.elementAt(i)); } /** Set and view the source code on the frame */ textPane.setEditable(false); textPane.setContentType("text/html; charset=EUC-JP"); subPanel2.setLayout(new GridLayout(0, 2)); subPanel2.add(firstBox); subPanel2.add(secondBox); subPanel3.setLayout(new GridLayout(0, 3)); subPanel3.add(exeButton); exeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExeCommand(); } }); subPanel3.add(resetButton); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doResetCommand(); } }); subPanel3.add(exitButton); exitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExitCommand(); } }); /** Run the illustrated program */ try { pid = program.exec(cmd); if (isWindows == false) { Process pid2 = null; pid2 = program.exec("getpid " + cmd.substring(4)); } } catch (IOException ie) { System.err.println("Couldn't run " + ie); // System.exit(-1);; } /** Set the initial status for the window */ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { File fp = new File(dataFile); doResetCommand(); boolean delete = fp.delete(); pid.destroy(); } }); doExeCommand(); setSize(WIDTH, HEIGHT); setLocation(500, 0); setVisible(true); }
// 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(); } } } }
/** * Try to determine whether this application is running under Windows or some other platform by * examining the "os.name" property. */ static { String os = System.getProperty("os.name"); // String version = System.getProperty("os.version"); // for Win7, reports "6.0" on JDK7, should // be "6.1"; for Win8, reports "6.2" as of JDK7u17 if (SystemUtils.startsWithIgnoreCase(os, "windows 7")) isWin7 = true; // reports "Windows Vista" on JDK7 else if (SystemUtils.startsWithIgnoreCase(os, "windows 8")) isWin7 = true; // reports "Windows 8" as of JDK7u17 else if (SystemUtils.startsWithIgnoreCase(os, "windows vista")) isVista = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows xp")) isWinXP = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows 2000")) isWin2k = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows nt")) isWinNT = true; else if (SystemUtils.startsWithIgnoreCase(os, "windows")) isWin9X = true; // win95 or win98 (what about WinME?) else if (SystemUtils.startsWithIgnoreCase(os, "mac")) isMac = true; else if (SystemUtils.startsWithIgnoreCase(os, "so")) isSolaris = true; // sunos or solaris else if (os.equalsIgnoreCase("linux")) isLinux = true; else isUnix = true; // assume UNIX, e.g. AIX, HP-UX, IRIX String osarch = System.getProperty("os.arch"); String arch = (osarch != null && osarch.contains("64")) ? "_x64" /* eg. 'amd64' */ : "_x32"; String syslib = SYSLIB + arch; try { // loading a native lib in a static initializer ensures that it is available before any // method in this class is called: System.loadLibrary(syslib); System.out.println( "Done loading '" + System.mapLibraryName(syslib) + "', PID=" + getProcessID()); } catch (Error e) { System.err.println( "Native library '" + System.mapLibraryName(syslib) + "' not found in 'java.library.path': " + System.getProperty("java.library.path")); throw e; // re-throw } if (isWinPlatform()) { System.setProperty( "line.separator", "\n"); // so we won't have to mess with DOS line endings ever again comSpec = getEnv( "comSpec"); // use native method here since getEnvironmentVariable() needs to know // comSpec comSpec = (comSpec != null) ? comSpec + " /c " : ""; try (BufferedReader br = new BufferedReader( new InputStreamReader( RUNTIME.exec(comSpec + "ver").getInputStream()))) { // fix for Win7,8 for (String line = null; (line = br.readLine()) != null; ) { if (isVista && (line.contains("6.1" /*Win7*/) || line.contains("6.2" /*Win8*/))) { isVista = false; isWin7 = true; } } } catch (IOException e) { e.printStackTrace(); } String cygdir = getEnv("cygdir"); // this is set during CygWin install to "?:/cygwin/bin" isCygWin = (cygdir != null && !cygdir.equals("%cygdir%")); cygstartPath = cygdir + "/cygstart.exe"; // path to CygWin's cygutils' "cygstart" binary if (getDebug() && Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); for (Desktop.Action action : Desktop.Action.values()) System.out.println( "Desktop action " + action + " supported? " + desktop.isSupported(action)); } } }
public BoxOnTable() { super(windowTitle); int i; Runtime program = Runtime.getRuntime(); Container content = getContentPane(); /** Get current OS of the system. */ if (System.getProperty("os.name").startsWith("Windows")) isWindows = true; else isWindows = false; /** Set interactive buttons for the user interface */ JButton exitButton = new JButton("Exit"); exitButton.setToolTipText("Exit the Program"); JPanel mainPanel = new JPanel(); content.add(mainPanel, BorderLayout.SOUTH); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); content.add(scrollPane, BorderLayout.CENTER); scrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); scrollPane.getViewport().add(textPane); mainPanel.add(exitButton, BorderLayout.CENTER); /** Set and view the source code on the frame */ textPane.setEditable(false); textPane.setContentType("text/html; charset=EUC-JP"); try { URL url = new URL("file:" + exampleSource); textPane.setPage(url); } catch (IOException ie) { System.err.println("Error in opening html source file " + ie); System.exit(-1); } exitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExitCommand(); } }); /** Run the illustrated program */ try { pid = program.exec(cmd); } catch (IOException ie) { System.err.println("Couldn't run " + ie); System.exit(-1); } /** Set the initial status for the window */ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { pid.destroy(); } }); setSize(WIDTH, HEIGHT); setLocation(500, 0); setVisible(true); }