hp19 发表于 2013-1-27 05:12:22

java中调用windows应用程序的简单实现

import java.io.*;
 
package exeCall;
 
public class call{
 
 Process child = null;
 String errMsg = "";
 
 public call(){
   
 }
 
 public void callProcess(String command){
     try{
         //String command = "C:\\Program\\NoteXPad\\NoteXPad.exe";
         child = Runtime.getRuntime().exec(command);
      }catch(IOException ioe){
          //System.out.println("IOException: "+ioe.getMessage()); 
          errMsg = errMsg + "IOException: "+ioe.getMessage();
      }catch(Exception e){
          //System.out.println("Exception: "+e.getMessage()); 
          errMsg = errMsg + "Exception: "+e.getMessage();
      }
 }
 
 public String getErrorMsg(){
     return errMsg; 
 }
 
   public static void main(String[] args){
      String commandStr = "D:\\program\\TheWorld\\TheWorld.exe";
      call c = new call();
      c.callProcess(commandStr);
     
      if(!(c.getErrorMsg()).equals("")){
            System.out.println("Error catched while calling \""+commandStr+"\"");
            System.out.println("details are as follows:");
            System.out.println(c.getErrorMsg()); 
      }
 
   } 
 
}
页: [1]
查看完整版本: java中调用windows应用程序的简单实现