Java调用Windows控制台命令计算机等级考试
文章作者 100test 发表时间 2010:01:28 11:54:09
来源 100Test.Com百考试题网
方法一:
public static void main(String[] args)
{
InputStream ins = null.
String[] cmd = new String[]{ "cmd.exe", "/C", "ipconfig" }.
try
{
Process process = Runtime.getRuntime().exec(cmd).
// cmd 的信息
ins = process.getInputStream().
BufferedReader reader = new BufferedReader(new InputStreamReader(
ins)).
String line = null.
while ((line = reader.readLine()) != null)
{
// 输出
System.out.println(line).
}
int exitValue = process.waitFor().
System.out.println("返回值:" exitValue).
// 关闭
process.getOutputStream().close().
}
catch (Exception e)
{
e.printStackTrace().
}