首页 > 编程语言 > 详细

java实现关闭windos系统下的进程

时间:2014-11-10 23:31:32      阅读:514      评论:0      收藏:0      [点我收藏+]

package com.cmd.core;


import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;


public class StreamGrabber extends Thread {  

 

private final InputStream stream;  

private final List<String> holder;  

 

public StreamGrabber(InputStream stream) {  

 this(stream, null);  

}  

 

public StreamGrabber(InputStream stream, List<String> holder) {  

 this.stream = stream;  

 this.holder = holder;  

}  

 

@Override  

public void run() {  

 try {  

  BufferedReader br = new BufferedReader(  

    new InputStreamReader(stream));  

  String line = null;  

  while ((line = br.readLine()) != null) {  

   if (holder != null)  

    holder.add(line);  

  }  

 } catch (IOException ioe) {  

  ioe.printStackTrace();  

 }  

}  

 

public static Process performCommand(String command) {  

 try {  

  return Runtime.getRuntime().exec(command);  

 } catch (IOException e) {  

  e.printStackTrace();  

  return null;  

 }  

}  

 

public static void main(String[] args) {  

 // notepa.exe关闭记事本进程  

 String command = "taskkill /f /im 11Game.exe";  

 Process proc = performCommand(command);  

 List<String> outputs = new ArrayList<String>();  

 new StreamGrabber(proc.getInputStream(), outputs).start();  

}  

}  


java实现关闭windos系统下的进程

原文:http://my.oschina.net/u/1778309/blog/342824

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!