1

I've seen many similar posts but I am still stumped. I want to run this shell script with a Java program :

C:\\Users\\pro-services\\Desktop\\projects\\github\\cygwin\\TEST.sh

Here's what the code looks like:

ProcessBuilder pb = new ProcessBuilder("C:\\Users\\pro-services\\Desktop\\projects\\github\\cygwin\\TEST.sh");
Process p = pb.start();

I am trying to use Process Builder but I'm not sure how to get it to work - I keep getting the error:

Cannot run program "C:\Users\pro-services\Desktop\projects\github\cygwin\TEST.sh": CreateProcess error=193, %1 is not a valid Win32 application

I know there are other fields of ProcessBuilder that I'm not using. I also know that there may be syntax issues here. I wrote my script for Cygwin. Any help please?

1

1 Answer 1

2

Instead of passing the script as an executable to ProcessBuilder, pass in the path to bash binary and pass your script as argument:

ProcessBuilder pb = new ProcessBuilder("C:\\path\\to\\bash.exe", "C:\\Users\\pro-services\\Desktop\\projects\\github\\cygwin\\TEST.sh");
Process p = pb.start();
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.