permaculture playing cards
The moose likes Java in General and the fly likes Can we call an executable(.exe) from Java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can we call an executable(.exe) from Java program" Watch "Can we call an executable(.exe) from Java program" New topic

Can we call an executable(.exe) from Java program

Swaroop Reddy
Ranch Hand

Joined: Feb 25, 2009
Posts: 34
Hello ,
I have an executable file written using Vc++ ,i want to call it in my java program in such a way it should get executed and should start working
Is it possible if so please suggest me relative links and process how to do

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10825

If you want to invoke some application, check out the Runtime and ProcessBuilder API.
Moving to a more appropriate forum

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
kiran kumar kondru

Joined: Feb 21, 2007
Posts: 3

I think the Runtime class encompasses the execution of native code. Runtime.getRuntime().exec("notepad.exe"); for example runs the notepad. Remember that either the exe is in the PATH or give complete path to it.

This exec() method returns a Process object through which you can have more control like killing the process itself.

The following is a sample program.

And Miles to go before I sleep<br />And Miles to go before I sleep
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

And please read the JavaWorld article "When Runtime.exec() won't". Once you start with external processes, this article is a must-read.

How To Ask Questions How To Answer Questions
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46383
The java.lang.ProcessBuilder class makes it easier, but it simplifies the problems discussed in the Daconta article Rob quoted. You still must read it.
I agree. Here's the link:
subject: Can we call an executable(.exe) from Java program
It's not a secret anymore!