1

I am getting some problem while executing binary executable file using Java code.

My Executable file is running perfectly on Terminal(Linux os) using following command

./ab0818 < ab0818.challenge

where "ab0818" is executable file and "ab0818.challenge" is input file.

I will get 0 exit code after running this command in terminal

My Code is Bellow.

System.out.println("Running the batch script");

Process p = Runtime.getRuntime().exec("./ab0818 < ab0818.challenge");
p.waitFor();
System.out.println("is.read() = "+p.exitValue());   

when I am run my code it will never come out of wait(waitFor()) process and my program never terminates.

My question is there any alternative way to execute command using java code or is there any modification needed in my code.

Thanks in Advance, -Viraj

1

1 Answer 1

1

Java doesn't know about the Linux shell's redirection operator "<".

You could try:

...exec("bash -c './ab0818 < ab0818.challenge'")

You might also want to look at http://download.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.html

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

2 Comments

Thanks this approach works for me. May I what bash -c command do?
It executes the bash shell, which in turn executes your program. Type "man bash" to see the manual page which describes all the options.

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.