Is it possible to execute binary files in java?
Asked Answered
A

3

11

I have a list of binaries written in Java, Ada, C, and Python and I want to execute them. How can I do that? Are there any JVM binding to those languages?

Autism answered 4/5, 2010 at 13:55 Comment(0)
N
14

If all you want to do is execute existing applictions, you can use the exec methods from the java.io.runtime namespace.

Runtime rt = Runtime.getRuntime();
Process ps = rt.exec("path to my executable.exe");
Nectareous answered 4/5, 2010 at 14:0 Comment(1)
For later versions it has moved to java.lang.Runtime.Belief
G
3

Yes. Here is a link to a good blog article on how to do it: Running system commands in Java.

The gist of it is that you need to do the following:

// run the Unix "ps -ef" command
// using the Runtime exec method:
Process p = Runtime.getRuntime().exec("ps -ef");

You can pretty much put any command in there but the only gotcha that I have encountered in be aware of system environment variables like the PATH that you are running your JVM in.

Geranium answered 4/5, 2010 at 14:0 Comment(1)
Updated (2010) version of that article: devdaily.com/java/java-exec-processbuilder-process-1Bursa
L
2

If you want to interact with the binary API's, use:

Lodie answered 4/5, 2010 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.