Reputation: 4695
I have a Java class that needs to kick off a child process. The child process is a class containing a main() method within the same project. I have:
Class clazz = RunMQCommands.class;
String separator = System.getProperty("file.separator");
String classpath = System.getProperty("java.class.path");
String path = System.getProperty("java.home");
ProcessBuilder pb =
new ProcessBuilder(path, "-cp",
classpath,
clazz.getCanonicalName());
pb.redirectErrorStream(true);
Process process = pb.start();
int retCode = process.waitFor();
And this gives me a
CreateProcess error=5, Access is denied
This is my first foray into ProcessBuilder. What am I doing wrong? I can kick off external things just fine (e.g. new ProcessBuilder("notepad"))
Upvotes: 2
Views: 577
Reputation: 280172
Your path
variable will have a value of something like
/usr/share/Java/1.8/jre
That is not an executable file.
Find the location of your executable java
file and give the value of that to your path
variable.
Your ProcessBuilder
should look like
ProcessBuilder pb =
new ProcessBuilder("/usr/share/Java/1.8/jre/java", "-cp",
classpath,
clazz.getCanonicalName());
Upvotes: 1