Java tutorial
//package com.java2s; /** * Copyright 2000-2006 DFKI GmbH. * All Rights Reserved. Use is subject to license terms. * <p/> * This file is part of MARY TTS. * <p/> * MARY TTS is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * <p/> * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * <p/> * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static int shellExecute(String strCommand) { return shellExecute(strCommand, true); } public static int shellExecute(String strCommand, boolean bDisplayProgramOutput) { Process p = null; try { p = Runtime.getRuntime().exec(strCommand); } catch (IOException e) { e.printStackTrace(); } if (p != null) { BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; try { line = input.readLine(); if (bDisplayProgramOutput && line != null) System.out.println(line); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } while (line != null) { try { line = input.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (bDisplayProgramOutput && line != null) System.out.println(line); } try { p.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return p.exitValue(); } return -1; } }