ikevin8me
ikevin8me

Reputation: 4313

Java unable to execute a bash shell script

I'm running into trouble trying to compile the eXo platform.

The error message is:

Caused by: java.io.IOException: Cannot run program "/exo/platform-public-distributions-develop/plf-community-tomcat-standalone/target/platform-community-5.0.x-SNAPSHOT/platform-community-5.0.x-SNAPSHOT/addon" (in directory "/exo/platform-public-distributions-develop/plf-community-tomcat-standalone"): error=2, No such file or directory

The directory is correct, the file indeed does exist, and permission is executable:

-rwxr-xr-x   1 root  wheel   3379 Sep  3 12:21 addon

That "addon" is a bash script.

I think the error mssage "No such file or directory" is erroneously reported. I saw this answer, but it is telling us to change the source code. Is there anyway to set some path for Java to execute the shell script?

Upvotes: 0

Views: 966

Answers (1)

pcarter
pcarter

Reputation: 1618

The bash script probably has a shebang (#!/bin/sh) at the top. This is normally interpreted by bash when invoking the script. However, running from java is not going to do this automatically. You will need to explicitly invoke bash to run the script.

You didn't post your code, but you need to set bash (or /bin/bash) as the executable and make the script be the first argument to bash. This will explicitly invoke bash to run the script. You need to execute:

/bin/bash /exo/platform-public-distributions-develop/plf-community-tomcat-standalone/target/platform-community-5.0.x-SNAPSHOT/platform-community-5.0.x-SNAPSHOT/addon

Upvotes: 1

Related Questions