大家好,我创建了一个 java 文件,在该 java 中,我编写了一个用于启动、停止和重新启动 Windows 服务的代码,因为我想创建一个日志文件并将窗口服务的输出写入控制台,如果有人知道,请给出建议我用代码停止服务
public static void stopService(String serviceName) throws IOException,
InterruptedException {
String executeCmd = "cmd /c net stop \"" + serviceName + "\"";
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
System.out.println("processComplete: " + processComplete);
if (processComplete == 1) {// if values equal 1 process failed
System.out.println("Service failed");
}
else if (processComplete == 0) {
System.out.println("Service Success");
}
}