.exe file from java
Hi all !!!
Is it possible to run a *.exe file from java.....
if yes how??
if no why not??
regards
ad
Yes. It's possible. One of the Runtime.exec() methods are probably what you want:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
You can't instantiate a Runtime object, so you'll need to call it up by:
Runtime.getRuntime()
For example, if you want to run the Calculator in Windows, try:
Runtime.getRuntime().exec("calc");
Similar Messages
-
I wants to call .Exe file from Java Programme
I wants to call .Exe file from Java programme. Please give answer with example. This very urgent. Help me
hi
u can use Runtime.exec() method in java.lang package
to execute exe files
regards
pnp -
Running exe files from java applications
Hello All,
Is it possible to run executable files from java applications?
I need to run an exe file on the client from the server machine, the exe could reside on either the server or any other machine on the LAN. Is it possible to specify the path of where the exe resides, and run it on a client machine?HI,
I tried to launch a MS Word application using runtime.exec but it gives me some problem
The foll. code to launch a txt file using notepad works.
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = {"notepad.exe","C:\\coo7\\wizard.txt"};
Process child = rt.exec(callAndArgs);
However, oif I try to launch a MS Word application, it asks for the entire path of WINWORD.exe, (unlike just specifying notepad.exe as the first argument in String[] callAndArgs) and this can vary from one machine to another.. how do I get around this?
The foll. code snippet works but the complete path of where WINWORD.exe might be installed on any machine, is not fixed:-(
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = {"C:\\Program Files\\Office\\Office10\\WINWORD.exe","C:\\coo7\\wizard.doc"};
Process child = rt.exec(callAndArgs);
Any idea/suggestions pls.. -
Hi , can anyone tell me how to run an exe file from my java program. the exe is in the same directory as my java files . When i click on a button i want to put something in the actionPerformed() method which will launch the exe file - prog.exe
Hope someone can help me.
Thanks JimHi !
Look at the RunTime class... -
heyy
can anybody please help me out in calling an exe file using java??
also i would like to pass parameters tooo.
i have been trying the following runtime code
but found no success
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("make.exe 12");
proc.waitFor();
int exitVal = proc.exitValue();
Does anybody havea better soultion???
Thanks for your time
RachitRead this article, please http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
-
Calling a function in an EXE file from Java Program
Hi Im having a function which is written in c program.i need to call that function from my java program, if i create a shared library (DLL) for my C code then it works but my requirement is i dont want to create that DLL , like in it would be an executable and my java code should access that function in that C program
I understand the usage od a DLL but the thing is if i convert the exe to a DLL
the server doesnt start at all so what i need is that i dont want to change
that .EXE into a .DLL,let it be an executable. that executable is in running mode
and through my java program i need to call a function in that EXE file.
Is ther any way to do it?Nope, but you have another problem: why can't you separate your server program
into a .dll part and a startup part? Both, when properly linked against each other
should give you an executable file.
kind regards,
Jos -
Running exe files from java progam
hi friends
I just want to know how can i run a .bat or .exe file in windows from a java program...
also i would like to know if i can check if mysql is installed in a windows computer from my java program
Thanks
Mustafasmshiraz wrote:
thanks Jos
now i am able to execute the .bat file.....from my java program
Can you also please tell me how can i check from my java program how if a particular application is installed in my windows computer??The exec() call will more than likely fail if the application is not present; again, read the API documentation.
kind regards,
Jos -
Running .EXE file from Java
Do you know, how run an .exe file, for example Internet Explorer or other program, from Java application?
It's very important for me.Too run external program and pass string arguments see class java doc
of java.lang.Runtime method exec . You see online or download or
rename src.jar to s.zip EXTRACT and see
exec
public Process exec(String[] cmdarray,
String[] envp)
throws IOException
Executes the specified command and arguments in a separate process with the
specified environment.
This is a convenience method. An invocation of the form exec(cmdarray, envp)
behaves in exactly the same way as the invocation exec(cmdarray, envp,
null).
Parameters:
cmdarray - array containing the command to call and its arguments.
envp - array of strings, each element of which has environment variable
settings in the format name=value, or null if the subprocess should inherit
the environment of the current process.
Returns:
A new Process object for managing the subprocess
Throws:
SecurityException - If a security manager exists and its checkExec method
doesn't allow creation of the subprocess
IOException - If an I/O error occurs
NullPointerException - If cmdarray is null, or one of the elements of
cmdarray is null, or one of the elements of envp is null
IndexOutOfBoundsException - If cmdarray is an empty array (has length 0)
See Also:
ProcessBuilder
getRuntime
public static Runtime getRuntime()
Returns the runtime object associated with the current Java application.
Most of the methods of class Runtime are instance methods and must be
invoked with respect to the current runtime object.
Returns:
the Runtime object associated with the current Java application. -
Executing exe files from java program
Hi,
I need to execute exe files and pass arguments to them from my java code.
Can you give me guidelines to do that as i haven't done that before.
Thanks.http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
getRuntime() method.
exec() method. -
Creating win 32 exe files from java class files
Hi I am using windows 2000.
I have developed a java swing gui application that has about 10 class files. I downloaded the microsoft sdk for java 4.0 for converting all my class files into a single .exe file. I used jexegen in this SDK to do this process. But when I double click the exe file, it just pops up and closes instantenously without showing my startup frame.
Can anyone help ?There is no Microsoft solution for this until you get J#, change your program
(J# is a little bit different that java but not much, it's closer to Java than C#)
and then compile to Win32 .exe.
For the refrence list of all Java to Native code compilers, check this page:
http://www.geocities.com/marcoschmidt.geo/jcomp.html#native :
Different from "normal" compilers (like javac or jikes), native compilers do not create bytecode files
(.class) that are interpreted by a Java Virtual Machine but native executables (like .exe files on
Windows). "How do I create an EXE from Java?" is a very frequently asked question in newsgroups
like comp.lang.java.programmer, native compilers are the answer. Some native compilers are listed
below, check them out. -
Creating exe files from java files
Hi all.
I've created a Java GUI file and I want to create an exe file of it, so i can just double click on the icon and opens up..
Anyway as to how i could do this?
Hope to hear from anyone. Would be a great help
Kind Regards,
Rahealhttp://forum.java.sun.com/thread.jspa?messageID=9783924
-
How to kill a .exe file from java !!
hi !!
how can i avoid duplicate use of a .exe file in jva ! i mean how can i kill duplicated copies sothat i wan allow only one copy ( one use ) at once !!
please help meA network port can only be used by one process at a time.
So you can use this as a marker or lock to tell if your program
is already running.
It's a hack, and won't work if anyone else choses the same
port you do, or if your program doesn't release the socket
cleanly when it exits.
amarshwren
import java.io.IOException;
import java.net.ServerSocket;
public class SocketTest
private static final int LOCK_PORT = 12345;
// replace this method with whatever you really want to do
private void doSomething()
System.out.println("Pretending to do something...");
try
synchronized (this)
while (true) this.wait();
catch (InterruptedException ex)
System.out.println("This won't happen.");
public static void main (String args[])
ServerSocket lockSocket = null;
try
lockSocket = new ServerSocket(LOCK_PORT);
catch (IOException ex)
System.err.println("An instance of SocketTest is already running.");
System.exit(-1);
SocketTest socketTest = new SocketTest();
socketTest.doSomething(); -
How to make exe files from java files
Ohhh, so you thought you were going to answer that question? Well I already know the answer, i.e. all the tricks with the jar files or the programs which convert java programs into executable programs.
The reason why I asked this question was to start a discussion concerning question which are frequently asked in the forums. Wouldn�t it be nice to have like statistics over the most faq here, and of course one or several pages with the answers to these questions? This would solve 2 problems:
1) The person who wants to ask the question can find the answer and the solution quickly.
2) The forums would not be packed with the same questions all the time.
I mean, you must admit that the questions regarding �exe files� are asked a lot of times.
Happy coding to ya all!
/TMYeah thats my point! these questions should be moved
to a special page, where the answer to theam areDid you the whole message? I said there are FAQs. -
Problem in Running EXE file from Java
Hello Friends,
I am calling an EXE program from my JSP page using Runtime.exec() method. The exe file simply reads a file and writes the content into another file (like copying a file). Now if I am providing fully qualified path to both source and destination files, then it runs absolutely fine. However, if i don't mention file path (only fine name is there), it creates output file in System32 folder and the resultant file doesn't contain any data.
I am providing the source for the EXE file.
==============
Source 1 (with fully qualified path name)
#include <stdio.h>
#include <fstream.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
void write_temp_file1(char *);
void main()
char * myTempPath=NULL;
myTempPath=(char *)calloc(100,sizeof(char));
strcpy(myTempPath,"D:\\temp\\tempFile.txt");
write_temp_file1(myTempPath);
myTempPath=NULL;
void write_temp_file1(char * fileName)
// first read the file and write another file with same content
char * line1=NULL;
char * line2=NULL;
char * line3=NULL;
line1=(char *)calloc(100,sizeof(char));
line2=(char *)calloc(100,sizeof(char));
line3=(char *)calloc(100,sizeof(char));
ifstream inf;
inf.open(fileName,ios::nocreate);
inf>>line1;
inf>>line2;
inf>>line3;
inf.close();
ofstream outf;
strcat(fileName, "1");
outf.open(fileName);
outf<<line1<<endl;
outf<<line2<<endl;
outf<<line3<<endl;
outf.close ();
================================
Scenario 2 (with file name only)
#include <stdio.h>
#include <fstream.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
void write_temp_file1(char *);
void main()
char * myTempPath=NULL;
myTempPath=(char *)calloc(100,sizeof(char));
strcpy(myTempPath,"my_temp_from_exe.txt");
write_temp_file1(myTempPath);
myTempPath=NULL;
void write_temp_file1(char * fileName)
// first read the file and write another file with same content
char * line1=NULL;
char * line2=NULL;
char * line3=NULL;
line1=(char *)calloc(100,sizeof(char));
line2=(char *)calloc(100,sizeof(char));
line3=(char *)calloc(100,sizeof(char));
ifstream inf;
inf.open(fileName,ios::nocreate);
inf>>line1;
inf>>line2;
inf>>line3;
inf.close();
ofstream outf;
strcat(fileName, "1");
outf.open(fileName);
outf<<line1<<endl;
outf<<line2<<endl;
outf<<line3<<endl;
outf.close ();
==========================
Can anyone figure out what could be the problem ? I think there is a problem with Library Path or sort of something like that.
Please help me.
-- Niranjanproviding source code for the EXE program doesn't tell your problem.
You have to be more specific. What is your problem? -
Need urgent help. Calling of exe files from java program
This program can execute small .exe files that donot take inputs but doesn't work for exe files that takes input. what could be the problem.
Server code :-
import java.io.*;
import java.net.*;
public class Server1 {
private Player[] players;
private ServerSocket server;
private ExecHelper exh;
String command = null;
String message = null;
public Server1() {
players = new Player[5];
try {
server = new ServerSocket( 12345, 5 );
System.out.println("Server started...");
System.out.println("Waiting for request...");
catch( IOException ioe ) {
ioe.printStackTrace();
System.exit( 1 );
} //end Server constructor
public void execute() {
for( int i = 0; i < players.length; i++ )
try {
players[i] = new Player( server.accept() );
players.start();
catch( IOException ioe ) {
ioe.printStackTrace();
System.exit( 1 );
public static void main( String args[] ) {
Server1 ser = new Server1();
ser.execute();
System.exit( 1 );
private class Player extends Thread {
private Socket connection;
private ObjectOutputStream output;
private ObjectInputStream input;
public Player( Socket socket ) {
connection = socket;
try {
input = new ObjectInputStream( connection.getInputStream());
output = new ObjectOutputStream( connection.getOutputStream());
output.flush();
catch( IOException ioe ) {
ioe.printStackTrace();
System.exit( 1 );
public void run() {
try {
message = "Enter a command:";
output.writeObject( message );
output.flush();
do {
command = ( String ) input.readObject();
String osName = System.getProperty( "os.name" );
String[] cmd = new String[3];
if( osName.equals( "Windows 2000" )) {
cmd[0] = "cmd.exe";
cmd[1] = "/c";
cmd[2] = command;
else if( osName.equals( "Windows NT" ) ) {
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = command ;
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec( cmd );
exh = new ExecHelper( proc, output, input);
} while( !command.equals( "TERMINATE" ) );
catch( Throwable t ) {
t.printStackTrace();
} //end class Player
public class ExecHelper implements Runnable {
private Process process;
private InputStream pErrorStream;
private InputStream pInputStream;
private OutputStream pOutputStream;
private InputStreamReader isr;
private InputStreamReader esr;
private PrintWriter outputWriter;
private ObjectOutputStream out;
private ObjectInputStream in;
private BufferedReader inBuffer;
private BufferedReader errBuffer;
private Thread processThread;
private Thread inReadThread;
private Thread errReadThread;
private Thread outWriteThread;
public ExecHelper( Process p, ObjectOutputStream output, ObjectInputStream input ) {
process = p;
pErrorStream = process.getErrorStream();
pInputStream = process.getInputStream();
pOutputStream = process.getOutputStream();
outputWriter = new PrintWriter( pOutputStream, true );
in = input;
out = output;
processThread = new Thread( this );
inReadThread = new Thread( this );
errReadThread = new Thread( this );
outWriteThread = new Thread( this );
processThread.start();
inReadThread.start();
errReadThread.start();
outWriteThread.start();
public void processEnded( int exitValue ) {
try {
Thread.sleep( 1000 );
catch( InterruptedException ie ) {
ie.printStackTrace();
public void processNewInput( String input ) {
try {
out.writeObject( "\n" + input );
out.flush();
catch( IOException ioe ) {
ioe.printStackTrace();
public void processNewError( String error ) {
try {
out.writeObject( "\n" + error );
out.flush();
catch( IOException ioe ) {
ioe.printStackTrace();
public void println( String output ) {
outputWriter.println( output + "\n" );
public void run() {
if( processThread == Thread.currentThread()) {
try {
processEnded( process.waitFor());
catch( InterruptedException ie ) {
ie.printStackTrace();
else if( inReadThread == Thread.currentThread() ) {
try {
isr = new InputStreamReader( pInputStream );
inBuffer = new BufferedReader( isr );
String line = null;
while(( line = inBuffer.readLine()) != null ) {
processNewInput( line );
catch( IOException ioe ) {
ioe.printStackTrace();
else if( outWriteThread == Thread.currentThread() ) {
try {
String nline = null;
nline = ( String ) in.readObject();
println( nline );
catch( ClassNotFoundException cnfe ) {
// cnfe.printStackTrace();
catch( IOException ioe ) {
ioe.printStackTrace();
else if( errReadThread == Thread.currentThread() ) {
try {
esr = new InputStreamReader( pErrorStream );
errBuffer = new BufferedReader( esr );
String nline = null;
while(( nline = errBuffer.readLine()) != null ) {
processNewError( nline );
catch( IOException ioe ) {
ioe.printStackTrace();
Client code :-
// client.java
import java.io.*;
import java.net.*;
public class Client {
private ObjectOutputStream output;
private ObjectInputStream input;
private String chatServer;
private String message = "";
private Socket client;
public Client( String host ) {
chatServer = host;
private void runClient() {
try {
connectToServer();
getStreams();
processConnection();
catch( EOFException eofe ) {
System.err.println( "Client terminated connection ");
catch( IOException ioe ) {
ioe.printStackTrace();
finally {
closeConnection();
} //end method runClient
private void connectToServer() throws IOException {
System.out.println( "Attempting connection...\n");
client = new Socket( InetAddress.getByName( chatServer ), 12345);
System.out.println( "Connected to : "+ client.getInetAddress().getHostName());
private void getStreams() throws IOException {
output = new ObjectOutputStream( client.getOutputStream());
output.flush();
input = new ObjectInputStream( client.getInputStream());
private void processConnection() throws IOException {
while( true ){
try {
message = ( String ) input.readObject();
System.out.print( message );
InputStreamReader isr = new InputStreamReader( System.in);
BufferedReader br = new BufferedReader( isr );
String line = null ;
line = br.readLine();
output.writeObject(line);
output.flush();
catch( ClassNotFoundException cnfe) {
System.out.println( "\nUnknown object type received");
} //end processConnection
private void closeConnection() {
System.out.println( "\nClosing connection");
try {
output.close();
input.close();
client.close();
catch( IOException ioe ) {
ioe.printStackTrace();
public static void main( String args[] ) {
Client c;
if( args.length == 0 )
c = new Client( "127.0.0.1" );
else
c = new Client( args[0] );
c.runClient();maybe you should
1. Use code tags so the posted code is understandable
2. Stop marking your post urgent, that just puts peoples backs up
3. Stop posting the question every couple of hours on every imaginable forum.. Post it once and start a single dialog
Maybe you are looking for
-
Using iMovie 7.1.4 on an iMac w/ Snow Leopard; HD video imported with a Firewire cable transfers fine, but audio arrives with major static; problem persists w/ different cameras & Firewire cables; source DV tape has no audfio static.
-
Soft I/O error in ASM disk volume when using iostat commmand
Dear All, We are having 2 node 11g rac/sun solaris 10/ASM storage, when we using iostat in node 2 getting soft I/O error keep on increasing. s/w h/w trn tot device *82 0 0 82 c4t600A0B80006766CD000003DF4B20A7FCd0* s/w h/w trn tot device 0 0 0 0 md/d1
-
Hi Frens Can any one help me the Jump target sample code in cmod Rgds
-
Interlace problem with DV PAL video
My video file is DV, 720 × 576 (768 × 576) with letterboxing I want to use compressor to resize this to 16:9 768 x 432, or 720 x 405 The original movie looks fine, but it seems whatever codec and whatever deinterlace setting in compressor, the outpu
-
Performance issue in APO Module
Hi All, While running the Demand Planning Book in APO Module, (Transaction Code :: <b>/n sdp94</b>) with 150 users, we faced a huge performance issue in both (while doing screen navigation & saving data). The planning book volume was for about 250 pr