您的位置:首页 > 编程语言 > Java开发

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

2014-11-11 08:36 204 查看
摘要: java实现关闭windos系统下的进程

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();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: