2

I face a problem to run a ".sh" file from my Java code, which is written in bash. At this point, I am using the following command to run the script (which is in the local directory, and seems to be found):

Process proc1 = Runtime.getRuntime().exec("./"+ nomScript);
proc1.waitFor();

But when executing, I get the error:

CreateProcess error=193, %1 n’est pas une application Win32 valide

(%1 is not a valid Win32 application, the whole error is in the code section below).

java.io.IOException: Cannot run program "./OAD_TCI_20_Blocage.sh": CreateProcess error=193, %1 n’est pas une application Win32 valide
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.coframi.oad.manager.ExecSuperviseur.gererBlocage(ExecSuperviseur.java:406)
at com.coframi.oad.manager.ExecSuperviseur.main(ExecSuperviseur.java:173)
Caused by: java.io.IOException: CreateProcess error=193, %1 n’est pas une application Win32 valide
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 5 more

I tried few things to run the script, as pointing the path to bash.exe as:

Process proc1 = Runtime.getRuntime().exec("pathTobash.exe -c "+ nomScript);

But nothing seems to work.

Does anyone know how I could run this script? Thank you

11
  • 2
    Well, are you trying to execute a ".sh" script in windows. Windows tell you that this is not a valid script, most likely because this is a script for a Unix. Can you execute the script without using Java ? Commented Apr 24, 2019 at 8:09
  • @AxelH No, I necessarily have to execute the script from java, because of the running of the application I work on. I found out that only files like '.exe', '.bat'... are considered as valid applications, but can't find any way to run directly the '.sh' Commented Apr 24, 2019 at 8:17
  • 3
    You don't get my point, if you can't execute that script on your OS, Java will not be able to help you because Runtime.exec will not translate anything, it will just run the process using the OS terminal. Commented Apr 24, 2019 at 8:20
  • 1
    Could you try "pathTobash.exe " + nomScript (that is, without -c)? Commented Apr 24, 2019 at 8:26
  • 1
    See linked answer for some working examples; basically you need to pass a String array with command and args, not a single string. Commented Apr 24, 2019 at 8:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.