2

I am trying to run a binary file, which is Genia Sequence Splitter through java code. This Binary file is type x-executable and has no extension. I can run the file in terminal by using ./geniass arg1 arg2 where arg1 is input file arg2 is output file I want to automate this process. I tried using this code

    public class geniaSSTag {
    public static void geniaSS(String inputFile){
        System.out.println("Input file: "+inputFile);

        String[]cmd={"bash","geniass/./geniass","in.txt","out.txt"};

        try {
            String errOutput="";
Process process = Runtime.getRuntime().exec(cmd);
String s = "";
BufferedReader br = new BufferedReader(new InputStreamReader(process
                        .getInputStream()));
while ((s = br.readLine()) != null)
{
   s += s + "\n";
}    
System.out.println(s);

BufferedReader br2 = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while (br2.ready() && (s = br2.readLine()) != null)
{
  errOutput += s;
}
System.out.println(errOutput);
        } catch (IOException ex) {
            Logger.getLogger(geniaSSTag.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

But I get this error when I try to run

geniass/./geniass: geniass/./geniass: cannot execute binary file

How can I solve this. Any help is appreciated.

Thank you

3
  • 1
    Is the file executable? Have you done a chmod +x filename? Commented Nov 29, 2011 at 14:54
  • 3
    did you try running it with absolute path? besides bash is unnecessary. Commented Nov 29, 2011 at 14:56
  • 2
    try with String[]cmd={"absolute-path-to-geniass","in.txt","out.txt"}; Commented Nov 29, 2011 at 14:56

3 Answers 3

1

When you run the program, is the executable relative to the program's starting directory in the manner that it lies in "./genias/genias"? Note that the "/./" doesn't do anything except waste space, as it is shorthand for "the subdirectory that links back to the current directory".

Perhaps your "genias" executable isn't in a subdirectory named "genias", or the launching program is being launched from a different directory and can't find "genias/genias" relative to it's directory.

As suggested elsewhere, you can fix this by using an absolute path in the launching command. However, sometimes this just isn't flexible enough if you want multiple copies installed.

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

Comments

0

I would try first to run the command pwd from Java to see where you actually are. Then you can change the path to your executable accordingly. I guess using the path /home/xxx/yyy/geniass would always work.

Also there is a different version of Runtime.exec() which takes a working directory as an argument.

Comments

0

Try:

String[]cmd={"/full/path/to/geniass","in.txt","out.txt"};

Instead

2 Comments

Also, use ProcessBuilder instead of Runtime.exec
Thanks everybody. I tried everything, but it keeps giving me the same error. So I wrote a script .sh and ran that instead which solved the problem. I have a hunch that it might be a permission error. But anyway things are fine now.

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.