In a java file I am calling command line statement to execute another java file. This is what I am doing:
List<String> paramsExecute = new ArrayList<String>(); paramsExecute.add("java"); paramsExecute.add("-cp"); paramsExecute.add("input\programs\User_K Program1"); paramsExecute.add("1 2 3"); ProcessBuilder builderExecute = new ProcessBuilder(paramsExecute); builderExecute.redirectOutput(new File(a.txt)); builderExecute.redirectError(new File(b.txt)); Execution of one of the Java files is producing b.txt as:
Error: Could not find or load main class 1 2 3 Another java file is producing b.txt as:
Usage: java [-options] class [args...] ... But, when I am running these statements directly from the command line, it is executing correctly. The folder input\programs\ is in the same path as the src folder. The src folder contains the Java file containing the ProcessBuilder program. I have verified that the .class file is getting created correctly and in the right folder. I am running the program in windows.
Any help appreciated!!