I’m attempting to run a bash script from my java test code, but I’m getting the following error.
<3>WSL (1114) ERROR: CreateProcessEntryCommon:505: execvpe /bin/bash failed 2
<3>WSL (1114) ERROR: CreateProcessEntryCommon:508: Create process not expected to return
Also the process exits with code 1.
The bash script:
#!/bin/bash
echo "hello"
And the Java code that calls the script:
private void configureDB() {
Process p;
try {
p = new ProcessBuilder("bash.exe", "./avm-database/test.sh").start();
} catch (IOException ignored) {
throw new RuntimeException(ignored);
// throw new RuntimeException("There was an error while rebuilding the database.");
}
// Define threads to capture output streams
Thread stdOutThread = new Thread(() -> captureStream(p.getInputStream(), System.out));
Thread stdErrThread = new Thread(() -> captureStream(p.getErrorStream(), System.err));
// Start the threads to capture output asynchronously
stdOutThread.start();
stdErrThread.start();
// Wait for the process to finish
try {
p.waitFor();
// Wait for the output capturing threads to finish as well
stdOutThread.join();
stdErrThread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// Now check the exit value and handle any errors
if (p.exitValue() != 0) {
throw new RuntimeException("Failed to build initial database with error code " + p.exitValue());
}
}
private static void captureStream(InputStream in, PrintStream out) {
Scanner scanner = new Scanner(in);
while (scanner.hasNextLine()) {
if (out != null) {
out.println(scanner.nextLine());
} else {
scanner.nextLine();
}
}
scanner.close();
}
(Stack overflow is requiring that I add more details because my post is mostly code, so here is an extra line of non-code text.)