0

I using Processbuilder as follows:

            List<String> args = initArgs();
            ProcessBuilder pb = new ProcessBuilder(args);
            tdmServerProcess = pb.start();

            handleInfoLog(tdmServerProcess.getInputStream());
            handleErrorLog(tdmServerProcess.getErrorStream());

In the initArgs method I am setting the linux commands I want to execute, as follows:

args.add("java -version");
args.add(javaHome + File.separator + "bin" + File.separator + "java");

first command is getting executed successfully. But second is failing with following error:

/opt/java7/bin/java: cannot execute binary file

though i have execute permission, following are permission bits:

-r-xr-xr-x 

I am able to execute the same command from terminal.

2 Answers 2

2

The error "cannot execute binary file" means that the java file is not valid. Maybe the 'java -version' is actually running java from another location in your path, and the /opt/java7/bin/java is not valid. Try running the '/opt/java7/bin/java' manually, and check the result. Check also the location of java in your path by running which java using the same user that your are running your java code with.

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

3 Comments

I am able to execute following command -bash-4.2$ /opt/java7/bin/java -version java version "1.7.0.09" Java(TM) SE Runtime Environment (build 1.7.0.09-jinteg_2014_02_03_13_09-b00) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03-jre1.7.0.09-rc1, mixed mode)
Then your code is running in a 32bit JVM. cannot execute binary file is usually caused for trying to run wrong binnaries for your arch. Just try which java to see what JVM are you really running.
which java gives me following: -bash-4.2$ which java /opt/java7/bin/java
0

You apparently are trying to execute two separate commands, first "java -version" and then "/opt/java7/bin/java" ?

That's not how it works. Rather, all of the arguments are appended and one process is started. In your case, the command is "java -version /opt/java7/bin/java"

Try running that at the console - I'm betting that you get the same error.

1 Comment

you are rite. its getting executed as java -version /opt/java7/bin/java. I tried the same on console. following is the output: -bash-4.2$ java -version /opt/java7/bin/java java version "1.7.0.09" Java(TM) SE Runtime Environment (build 1.7.0.09-jinteg_2014_02_03_13_09-b00) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03-jre1.7.0.09-rc1, mixed mode)

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.