怎么将DOS下的返回结果重定向到一个新的GUI界面 各位高手: 请教一个很深奥的问题.要求: 在DOS下通过命令行返回的查询结果,反映在一个新的GUI界面上,并且,界面上还需要设置一些可以可执行的参数组合,通过组合能够在DOS中执行,并及时返回界面. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在程序中调用dos命令,并返回结果:String command = "cmd.exe /c ver";Process p = Runtime.getRuntime().exec(command);BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); 但是我不是要在程序中调用dos命令,而是先在dos下输入命令,然后,将查询的结果以参数的形式返回到gui界面上. 晕倒,在一个Dos界面操作,让Java GUI来监听且显示?方法1:两个进程间的通讯,用C来做中间人;方法2:将Dos执行结果先重定向到一个文件,java来检视该文件,若有变动,则显示;方法3:用java模拟Dos输入命令且得到结果,即用mq612(五斗米)老大的,增加OutputStream 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; } } } SWT/JFace 程序的国际化实现 Jfreechart饼图,鼠标所在部分突出显示问题 对于使用了html标签的表单,如何用js验证是否为空并弹出消息框 String输出字符串,如果把其中的字符 取出放到一个数据组里 请教一个关于字符串的问题 问一个Eclipse JUnit测试问题 我快要气死了,我的Eclipse总是启动不了, applet客户端(IE)与服务器端JDK版本不一致的问题 jdbc连Sqlserver2000的问题 一百分求解 :一个关于句柄的问题!!! 我的数组怎么引用不了? jsp怎么实现文件上传和页面的值传递???
String command = "cmd.exe /c ver";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
方法1:两个进程间的通讯,用C来做中间人;
方法2:将Dos执行结果先重定向到一个文件,java来检视该文件,若有变动,则显示;
方法3:用java模拟Dos输入命令且得到结果,即用mq612(五斗米)老大的,增加OutputStream
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;
}
}
}