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();
- }
- }