/*
 * Created on 2005-5-12
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.chapter2;

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CallOtherApp {

	public static void main(String[] args) {
		/*
		Process process;
		try {
			process = Runtime.getRuntime().exec("cmd /c start excel java.xls");
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		*/
		CallOtherApp.executePing("127.0.0.1");
	}
	
	public static void executePing(String dest){
		String cmd ="ping " + dest;             //命令字符串
		Process process ;
		try{
			process = Runtime.getRuntime().exec(cmd);    //直接执行shell的ping程序
			//取得子进程的输出
			BufferedReader reader= new BufferedReader(new InputStreamReader(process.getInputStream()));
			String message = "";
			String str;
			while((str = reader.readLine()) != null){
				System.out.println( str );
			}
			try { 
				process.waitFor(); 
			}catch (InterruptedException e) { 
				System.err.println("process was interrupted"); 
			} 
		}catch(Exception e){
			e.printStackTrace();
		}	
	}
}
