samedi 20 septembre 2014

Buffered reader to string builder or apache commons.io


Vote count:

0




I got this method to check service states:



private int checkService(String SERVICE_NAME) {
String[] script = {"cmd.exe", "/c", "sc", "query", SERVICE_NAME, "|", "find", "/C", "\"RUNNING\""};
int s = 0;
try {
Process p = Runtime.getRuntime().exec(script);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
String starting = "START_PENDING";
String stopping = "STOP_PENDING";
while (line != null) {
if (line.toLowerCase().contains(starting.toLowerCase())) {
s = 3;
}
if (line.toLowerCase().contains(stopping.toLowerCase())) {
s = 2;
}
if (line.equals("0")) {
s = 0;
}
if (!line.equals("0")) {
s = 1;
}
line = reader.readLine();
}

} catch (IOException | InterruptedException e1) {
System.out.println(e1);
}
return s;
}


I want to make this line work:



if (line.toLowerCase().contains(starting.toLowerCase()))


but i cannot find a string in "line" because "line" is not a string... I want to catch this:



SERVICE_NAME: OracleServiceORCL
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x7d0
PID : 4144
FLAGS :


3rd line START_PENDING is what im looking for, depending on the service state the actions should be different. I have tried converting the bufferedReader with apache commons.io but it just prints white spaces... How can i properly change this code so that this info becomes a string?



asked 2 mins ago







Buffered reader to string builder or apache commons.io

Aucun commentaire:

Enregistrer un commentaire