2007-10-15
菜鸟日记之java运行bat文件
java 代码
package startbat;
import java.io.IOException;
import java.io.InputStream;
public class RunBat {
public void RunBatFile(){
String command = "D:\\test.bat";
//String command = "D:\\test.bat";
try {
Process child = Runtime.getRuntime().exec(command);
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(c);
}
in.close();
try {
child.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("done");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.io.InputStream;
public class RunBat {
public void RunBatFile(){
String command = "D:\\test.bat";
//String command = "D:\\test.bat";
try {
Process child = Runtime.getRuntime().exec(command);
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(c);
}
in.close();
try {
child.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("done");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java 代码
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- try {
- String ot = request.getParameter("operType") == null ? "" : request.getParameter("operType");
- PrintWriter out = response.getWriter();
- //if (ot == "start"){
- RunBat rb = new RunBat();
- rb.RunBatFile();
- request.getRequestDispatcher("/success.jsp").forward(request,
- response);
- //}
- out.flush();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
发表评论
- 浏览: 8056 次
- 来自: 卡利姆多

- 详细资料
搜索本博客
最新评论
-
菜鸟日记之动态action
你的这文章还是没看懂意思 能不能说的详细点!!!
-- by zhaojuan8 -
[转]给浮躁的人一点建议 ...
Re一个,很早就看过这篇文章了,很实在
-- by ronn -
菜鸟日记之利用java往注册 ...
感谢回贴 后来决定用ActiveX解决了
-- by protti -
菜鸟日记之利用java往注册 ...
http://ldjsyl.javaeye.com/admin/show/822 ...
-- by ldjsyl -
菜鸟日记之利用java往注册 ...
目前存在的问题是 读取出来的value不支持中文 提取出来存在编码问题 ...
-- by protti






评论排行榜