你好请问java如何调用bat文件,并传递参数啊……我的qq474659049 谢谢你了
1个回答
2012-06-27
展开全部
找了个例子:
bat文件:
@echo off
cd c:\
echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "open %1{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "%2{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "%3{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "reboot{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "exit{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 5000 >>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "q{ENTER}">>telnet_tmp.vbs
start telnet
cscript //nologo telnet_tmp.vbs
del telnet_tmp.vbs
action:
String path=ServletActionContext.getServletContext().getRealPath("//WEB-INF//classes//reboot.bat");
String command=path+" "+this.getIp()+" "+this.remotName+" "+this.remotPassword;
try {
Process ps = Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
bat文件:
@echo off
cd c:\
echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
echo WScript.Sleep 300 >>telnet_tmp.vbs
echo sh.SendKeys "open %1{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "%2{ENTER}" >>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "%3{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "reboot{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "exit{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 5000 >>telnet_tmp.vbs
echo sh.SendKeys "{ENTER}">>telnet_tmp.vbs
echo WScript.Sleep 3000 >>telnet_tmp.vbs
echo sh.SendKeys "q{ENTER}">>telnet_tmp.vbs
start telnet
cscript //nologo telnet_tmp.vbs
del telnet_tmp.vbs
action:
String path=ServletActionContext.getServletContext().getRealPath("//WEB-INF//classes//reboot.bat");
String command=path+" "+this.getIp()+" "+this.remotName+" "+this.remotPassword;
try {
Process ps = Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询