Skip to content

Commit

Permalink
0003510: Service wrapper hanging on start on Windows 2003 server
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Apr 6, 2018
1 parent 0ac0016 commit af07d38
Showing 1 changed file with 14 additions and 7 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -190,18 +191,24 @@ protected boolean isPidRunning(int pid) {
try {
ProcessBuilder pb = new ProcessBuilder("wmic", "process", String.valueOf(pid), "get", "name");
Process proc = pb.start();
pb.redirectErrorStream(true);
BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null, curLine = null;
boolean isHeaderLine = true;
while ((curLine = stdout.readLine()) != null) {
if (isHeaderLine) {
isHeaderLine = false;
} else if (line == null && !curLine.trim().equals("")) {
line = curLine;
curLine = stdout.readLine();
if (curLine != null && !curLine.trim().equals("")) {
while ((curLine = stdout.readLine()) != null) {
if (line == null && !curLine.trim().equals("")) {
line = curLine;
break;
}
}
}
while (stdout.read() != -1) {
}
stdout.close();
InputStream errout = proc.getErrorStream();
while (errout.read() != -1) {
}
errout.close();

if (line != null) {
String[] array = line.split("\\s+");
Expand Down

0 comments on commit af07d38

Please sign in to comment.