Java 调用Linux 系统关机命令

来源:互联网 发布:淘宝未评价就删除订单 编辑:程序博客网 时间:2024/06/09 19:43

在Fedora 上测试通过 

 

import java.io.*;
public class RunPing {

 public static void main(String[] argv) {
  try {
   Runtime runtime=Runtime.getRuntime();
   Process process=runtime.exec("halt -p");
   BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
   String line;
   while((line=reader.readLine())!=null) {
    System.out.println(line);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

原创粉丝点击