执行 cmd /c start F:\\abc.bat > out.txt
然后打开out.txt查看
然后打开out.txt查看
解决方案 »
- java.lang.NullPointerException处理
- ie 火狐 对cookie的影响
- 求救,Hibernate生成映射文件过程报错,迟迟找不出原因,崩溃了
- 各位,能否帮忙解决一个url参数问题?
- 请教过滤器问题
- ckeditor3文件上传功能 以及浏览服务器按钮怎么没了?
- 关于spring+Xfire开发的webservice
- 大师们,帮我看看这段代码是否能正常运行。
- 没有办法了,哪位知道哪里能下MYSQL的JAVA驱动?在线等急.3X了!
- kongxinmutou(空心木头)请进 谁能简单介绍一下j2ee的开发构架 !
- 页面转向问题?急!
- 求助,使用httpclient实现登陆的问题,高手来看看
執行時的輸出信息急,自己給自己頂下
public static void main(String[] args) {
try{
String command = "notepad.exe";
Process child = Runtime.getRuntime().exec(command);
child.waitFor();
}catch(Exception e){
System.err.println(e.getMessage());
}
}
}
调用.exe,.bat都一样
child.getInputStream()
搞错方向了
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;public class JavaExeBat {
public JavaExeBat() {
} public static void main(String[] args) {
Process p;
//test.bat中的命令是ipconfig/all
String cmd="c:\\test\\test.bat";
try {
//执行命令
p = Runtime.getRuntime().exec(cmd);
//取得命令结果的输出流
InputStream fis=p.getInputStream();
//用一个读输出流类去读
InputStreamReader isr=new InputStreamReader(fis);
//用缓冲器读行
BufferedReader br=new BufferedReader(isr);
String line=null;
//直到读完为止
while((line=br.readLine())!=null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
如果如下:
Windows IP Configuration Host Name . . . . . . . . . . . . : Mickey Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Unknown IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No DNS Suffix Search List. . . . . . : domainEthernet adapter 本地连接: Connection-specific DNS Suffix . : domain Description . . . . . . . . . . . : Broadcom NetXtreme Gigabit Ethernet Physical Address. . . . . . . . . : 00-18-71-6C-0C-7D DHCP Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.1.103 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1 DHCP Server . . . . . . . . . . . : 192.168.1.1 DNS Servers . . . . . . . . . . . : 202.96.134.133 202.96.128.68 Lease Obtained. . . . . . . . . . : 2007年7月4日 14:53:56 Lease Expires . . . . . . . . . . : 2007年7月4日 16:53:56