I have an application that calls a java test class in a specified location of my PC. The path is hard-coded for now, and I checked that it worked by executing it from the command line (in case you want to see it: java -cp C:\Users\user\Documents\workspace\test\build\test.jar org.junit.runner.JUnitCore us.test.DynamicWebserviceInvocationTest), so I know that the command works fine.
The thing is, when I do Runtime.getRuntime().exec(command), if I try to log the resulting InputStream and ErrorStream of its resulting process, the program stucks. I tried with exitValue() and waitFor(), but the first throws an incompletition error and the second also gets stuck. The weird thing is that if I don't touch anything of this (the streams, or using the functions), the program has no problem ending.
So my question is: Why could this be? The next step is to build the command with given parameters, but if I can't see the resulting inputs I can't be completely sure if the tests are running or not.
The code, in case you want to see it:
Runtime runtime=Runtime.getRuntime(); logger.debug("Attempting to execute the test {} at path {}",classpath,applicationLocation);
String command="java -cp C:\\Users\\user\\Documents\\workspace\\test\\build\\test.jar org.junit.runner.JUnitCore us.test.DynamicWebserviceInvocationTest";
Process process=runtime.exec(command);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(process.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
Aucun commentaire:
Enregistrer un commentaire