各位高手:
   请教一个很深奥的问题.要求:
   在DOS下通过命令行返回的查询结果,反映在一个新的GUI界面上,并且,界面上还需要设置一些可以可执行的参数组合,通过组合能够在DOS中执行,并及时返回界面.

解决方案 »

  1.   

    在程序中调用dos命令,并返回结果:
    String command = "cmd.exe /c ver";
    Process p = Runtime.getRuntime().exec(command);
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
      

  2.   

    但是我不是要在程序中调用dos命令,而是先在dos下输入命令,然后,将查询的结果以参数的形式返回到gui界面上.
      

  3.   

    晕倒,在一个Dos界面操作,让Java GUI来监听且显示?
    方法1:两个进程间的通讯,用C来做中间人;
    方法2:将Dos执行结果先重定向到一个文件,java来检视该文件,若有变动,则显示;
    方法3:用java模拟Dos输入命令且得到结果,即用mq612(五斗米)老大的,增加OutputStream
      

  4.   

    public class ExecCommond{ 
    public ExecCommond(){} 
    /** 
    * 执行一条命令 
    * @param execStr String 命令字符串 
    * @return String 执行命令错误时的信息。 
    */ 
    public static String exec(String execStr) { 
    Runtime runtime = Runtime.getRuntime(); 取得当前运行期对象 
    String outInfo=""; //执行错误的输出信息 
    try { 
    String[] args = new String[] {"sh", "-c", execStr};//执行linux下的命令 
    //执行windows下的命令 
    // String[] args = new String[] {"cmd", "-c", execStr}; 
    Process proc = runtime.exec(args); //启动另一个进程来执行命令 
    InputStream in = proc.getErrorStream();//得到错误信息输出。 
    BufferedReader br = new BufferedReader(new InputStreamReader(in)); 
    String line = ""; 
    while ( (line = br.readLine()) 
    != null) { 
    outInfo = outInfo + line + "\n"; 
    System.out.println(outInfo); 

    // 检查命令是否失败。 
     
    try { 
    if (proc.waitFor() != 0) { 
    System.err.println("exit value = " + 
    proc.exitValue()); 


    catch (InterruptedException e) { 
    System.err.print(e); 
    e.printStackTrace(); 


    catch (IOException e) { 
    flag = false; 
    System.out.println("exec error: " + e.getMessage()); 
    e.printStackTrace(); 

    finally { 
    return outInfo; 


    }