3

I'm on Windows, and i try to work on a Java application that was written to be use on a Linux OS, because the program will launch some shell script at some point.

I have WSL (Windows Subsystem for Linux, also know as Ubuntu bash), so executing shell script should not be a problem, but i have an error : 0x80070057

The code that launch the external process :

public Process startProcess(List<String> commands ) throws IOException {
    ProcessBuilder etProcessBuilder= new ProcessBuilder(commands);
    Process etProcess = etProcessBuilder.start();
    ProcessOutputReader stdReader= new ProcessOutputReader(etProcess.getInputStream(), LOGGER::info);
    ProcessOutputReader errReader= new ProcessOutputReader(etProcess.getErrorStream(), LOGGER::error);
    new Thread(stdReader).start();
    new Thread(errReader).start();
    return etProcess;
}

The commands param are set with with something like this :

  • "/mnt/d/some/path/scripts/initEAF.sh"
  • "-argForTheScript"
  • "some value"
  • "-anotherArg"
  • "other value"

I also tried to add "bash.exe" as first command, but it doesn't seems to work.

The ProcessOutputReaderis a class to log the stream from the process

class ProcessOutputReader implements Runnable {
    private final InputStream inputStream;
    private Consumer<String> loggingFunction;

    ProcessOutputReader(InputStream inputStream, Consumer<String> loggingFunction) {
        this.inputStream = inputStream;
        this.loggingFunction = loggingFunction;
    }

    private BufferedReader getBufferedReader(InputStream is) {
        return new BufferedReader(new InputStreamReader(is));
    }

    @Override
    public void run() {
        BufferedReader br = getBufferedReader(inputStream);
        String ligne;
        try {
            while ((ligne = br.readLine()) != null) {
                loggingFunction.accept(ligne);
            }
        } catch (IOException e) {
            LOGGER.error("Error occur while reading the output of process ", e);
        }
    }
}

Any idea is welcome.

1 Answer 1

1

*.sh is not an executable file. You need run it by a shell, such as bash xxx.sh -args or sh xxx.sh -args if your java app run inside wsl.

If your java app run on Windows, it should be bash.exe -c xxx.sh

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.