远程执行本地命令
package com.sunshine.cmd;
/**
* @(#)ExecCMD.java
*
* execute cmd.exe with import command string
* @sundyt tu
* @version 1.00 2009/4/8
*/
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
public class ExecCMD {
/**
* Creates a new instance of <code>ExecCMD</code>.
*/
public ExecCMD(){
// do nothing;
}
public String RunCmd(String command){
try
{
Process sundyObj;
sundyObj = Runtime.getRuntime().exec("cmd.exe /c \"" + command + "\"\r");
InputStream ProcessInfor = sundyObj.getInputStream();
Scanner InforRead = new Scanner(ProcessInfor);
StringBuffer sb = new StringBuffer("");
while(InforRead.hasNextLine())
{
sb.append(InforRead.nextLine() + "\r");
}
System.out.println(sb.toString());
return sb.toString();
}
catch (IOException e)
{
System.out.print(e.toString());
}
return "";
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
// TODO code application logic here
ExecCMD obj = new ExecCMD();
obj.RunCmd("ping 127.0.0.1 && dir && cd D:\\ && dir");
}
}
<%@ page language="java" import="java.util.*" contentType="text/html; charset=GBK"%>
<%@page import="com.sunshine.cmd.ExecCMD"%>
<html>
<head>
<title>远程执行测试页面</title>
</head>
<body>
<%
String status = "";
try {
String tmp = request.getParameter("cmd");
status = new String(tmp.getBytes("ISO-8859-1"), "GBK");
System.out.println("OK\r");
ExecCMD sundy = new ExecCMD();
status = sundy.RunCmd(status);
} catch (Exception OO) {
System.out.println(OO.toString());
}
%>
<form method="POST" action="cmdTest.jsp">
执行结果
<table>
<tr>
<td><%=status%></td>
</tr>
</table>
<br>
<input name="cmd" type="text" size="40">
<br>
<input type="submit" value="执行命令">
</form>
</body>
</html>
- (10-02-25 00-00)Onunload与Onbeforeunload
- (10-02-25 00-00)改变mysql数据包1M的限制
- (10-02-25 00-00)jQuery-位置选择器
- (10-02-25 00-00)jQuery-位置选择器
- (10-02-25 00-00)jQuery-创建元素包装集
- (10-02-25 00-00)jQuery-引荐
- (10-02-25 00-00)jQuery-AJAX
- (10-02-25 00-00)宕机的原因有哪几种,怎么样分析宕机的原因
- (10-02-25 00-00)http和https的区别
- (10-02-25 00-00)内部跳转和外部跳转的区别,底层实现原理