質問

いるJavaとその応用については、走り勝てる過程に知っている名称の実行形式にまとめたものです。私が見たいと思いるかどうかではそれが必要な"釣りスタ"なら釣りのプロセスがいのでしょう。

役に立ちましたか?

解決

利用できるコマンドラインのwindowsのツール tasklisttaskkill 呼び出しからJavaを使用 Runtime.exec().

他のヒント

private static final String TASKLIST = "tasklist";
private static final String KILL = "taskkill /F /IM ";

public static boolean isProcessRunning(String serviceName) throws Exception {

 Process p = Runtime.getRuntime().exec(TASKLIST);
 BufferedReader reader = new BufferedReader(new InputStreamReader(
   p.getInputStream()));
 String line;
 while ((line = reader.readLine()) != null) {

  System.out.println(line);
  if (line.contains(serviceName)) {
   return true;
  }
 }

 return false;

}

public static void killProcess(String serviceName) throws Exception {

  Runtime.getRuntime().exec(KILL + serviceName);

 }

例:

public static void main(String args[]) throws Exception {
 String processName = "WINWORD.EXE";

 //System.out.print(isProcessRunning(processName));

 if (isProcessRunning(processName)) {

  killProcess(processName);
 }
}

がありませんが、APIの提供をご希望の機能:

https://github.com/kohsuke/winp

Windowsプロセス図書館

するコマンドラインツールで殺害のようなプロセス SysInternals PsKillSysInternals PsList.

きものにtasklist.exe やtaskkill.exeものみとなっておりますWindows XP Professional以降なのである必要はありません。

使用 java.lang.を行います。exec を実行します。

このgroovyはそ:

final Process jpsProcess = "cmd /c jps".execute()
final BufferedReader reader = new BufferedReader(new InputStreamReader(jpsProcess.getInputStream()));
def jarFileName = "FileName.jar"
def processId = null
reader.eachLine {
    if (it.contains(jarFileName)) {
        def args = it.split(" ")
        if (processId != null) {
            throw new IllegalStateException("Multiple processes found executing ${jarFileName} ids: ${processId} and ${args[0]}")
        } else {
            processId = args[0]
        }
    }
}
if (processId != null) {
    def killCommand = "cmd /c TASKKILL /F /PID ${processId}"
    def killProcess = killCommand.execute()
    def stdout = new StringBuilder()
    def stderr = new StringBuilder()
    killProcess.consumeProcessOutput(stdout, stderr)
    println(killCommand)
    def errorOutput = stderr.toString()
    if (!errorOutput.empty) {
        println(errorOutput)
    }
    def stdOutput = stdout.toString()
    if (!stdOutput.empty) {
        println(stdOutput)
    }
    killProcess.waitFor()
} else {
    System.err.println("Could not find process for jar ${jarFileName}")
}

以下のクラス 殺しのWindowsロ (の場合は走行).私が使っている力のコマンドライン引数 /F させることによって処理で指定された /IM 引数を終了させていただきます。

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class WindowsProcess
{
    private String processName;

    public WindowsProcess(String processName)
    {
        this.processName = processName;
    }

    public void kill() throws Exception
    {
        if (isRunning())
        {
            getRuntime().exec("taskkill /F /IM " + processName);
        }
    }

    private boolean isRunning() throws Exception
    {
        Process listTasksProcess = getRuntime().exec("tasklist");
        BufferedReader tasksListReader = new BufferedReader(
                new InputStreamReader(listTasksProcess.getInputStream()));

        String tasksLine;

        while ((tasksLine = tasksListReader.readLine()) != null)
        {
            if (tasksLine.contains(processName))
            {
                return true;
            }
        }

        return false;
    }

    private Runtime getRuntime()
    {
        return Runtime.getRuntime();
    }
}

また電話のネイティブコードからぁありません図書館なのです。以来、JNIるのが面倒、ハードが利用するようにしてJNA(Java Nativeアクセス)などです。 https://jna.dev.java.net/

小さな変化に答えが書いたスーパー kakes

private static final String KILL = "taskkill /IMF ";

変更..

private static final String KILL = "taskkill /IM ";

/IMF オプションdoesnotます。ないのでメモ帳が.. /IM オプションを実際に作品

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top