有这么一个问题: 谢谢帮忙!!!!运用java 程序实现关机,//运行本地关机命令,会出现提示输入密码框
Process process=(java.lang.Runtime.getRuntime()).exec("runAs /env /user:administrator \"shutdown -s -t 90\"");怎么将手工输入转化成 程序输入?以下是测试代码import java.io.*;public class Watch_taskManager extends Thread
{
private static final boolean DEBUG=true; private static void println(String string)
{
if (DEBUG)
{
System.out.println(string);
}
} public static void main(String args[])
{
try
{
println("开始运行。");
//运行本地关机命令,会出现提示输入密码框
Process process=(java.lang.Runtime.getRuntime()).exec("runAs /env /user:administrator \"shutdown -s -t 90\"");
//process.waitFor();
//获得线程的输入输出流
InputStream input=process.getInputStream();
OutputStream output=process.getOutputStream();
BufferedReader inStr=new BufferedReader(new InputStreamReader(input));
println((String)inStr.readLine());
PrintStream bu=new PrintStream(output);
//输入密码,但是不行
output.write(("shuxueyuan"+"\n").getBytes());
output.flush();
println((String)inStr.readLine());
println("结束运行。");
}
catch(SecurityException e)
{
println("Security:"+e.getMessage());
}
catch(IOException e1)
{
println("IOException:"+e1.getMessage());
}
catch(NullPointerException e2)
{
println("NullPointerException"+e2.getMessage());
}
catch(IllegalArgumentException e3)
{
println("IllegalArgumentException"+e3.getMessage());
}
catch(Exception e)
{
println(e.getMessage());
}
}
};
Process process=(java.lang.Runtime.getRuntime()).exec("runAs /env /user:administrator \"shutdown -s -t 90\"");怎么将手工输入转化成 程序输入?以下是测试代码import java.io.*;public class Watch_taskManager extends Thread
{
private static final boolean DEBUG=true; private static void println(String string)
{
if (DEBUG)
{
System.out.println(string);
}
} public static void main(String args[])
{
try
{
println("开始运行。");
//运行本地关机命令,会出现提示输入密码框
Process process=(java.lang.Runtime.getRuntime()).exec("runAs /env /user:administrator \"shutdown -s -t 90\"");
//process.waitFor();
//获得线程的输入输出流
InputStream input=process.getInputStream();
OutputStream output=process.getOutputStream();
BufferedReader inStr=new BufferedReader(new InputStreamReader(input));
println((String)inStr.readLine());
PrintStream bu=new PrintStream(output);
//输入密码,但是不行
output.write(("shuxueyuan"+"\n").getBytes());
output.flush();
println((String)inStr.readLine());
println("结束运行。");
}
catch(SecurityException e)
{
println("Security:"+e.getMessage());
}
catch(IOException e1)
{
println("IOException:"+e1.getMessage());
}
catch(NullPointerException e2)
{
println("NullPointerException"+e2.getMessage());
}
catch(IllegalArgumentException e3)
{
println("IllegalArgumentException"+e3.getMessage());
}
catch(Exception e)
{
println(e.getMessage());
}
}
};
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货