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.
Similar Messages
-
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.. -
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 -
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? -
Hi all !!!
Is it possible to run a *.exe file from java.....
if yes how??
if no why not??
regards
adYes. 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"); -
Running .nsi file from java
hi,
Ho to run .nsi file from java.
thanks in advance.User845466 wrote:
Ho to run .nsi file from java.Find the program hanling that kind of documents an launch this via Runtime.exec() giving it your *.nsi file as a parameter.
bye
TPD -
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 -
Can we run EXE file/ Another Java Program from Java Application? How?
Can we run EXE file and another java program from java application?
Thanks in advanceExample running adobe acrobat
String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
Runtime rn = Runtime.getRuntime();
Process process = rn.exec(command);
process.waitFor();rykk -
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... -
How to run exe file from inside java
I wan to run an exe file from inside java code. How can I do it?
ThanksHi Oakam
This is very simple. Just go through the given code below
in place of FILEANDPATHNAME just give the exe's path and name
Note :- adding ".exe " is not necessary
public class exep
public static void main(String args[])
Runtime r = Runtime.getRuntime();
Process p = null;
try{
p = r.exec("FILEANDPATHNAME");
catch(Exception e)
Give ur feedback
Thanx
Ottran -
Error running batch files from java source file???
Dear Friends,
hi,
this is with response to a doubt i had earlier ,
i want to run batch files from the java source file ,i tried using this code (here batrun is the batch file name that contains commands to run other java files)
try
String [] command = {"c:\\vishal\\finalmain\\batrun"};
Runtime.getRuntime().exec(command);
catch(Exception e)
but i got the following error.
java.io.IOException: CreateProcess: gnagarrun error= 2
plz. help me, i tried all combination w/o success,
in anticipation(if possible give the code after testing)
Vishal.hello there,
i solved the prob. by using
cmd /c start filename ,but i need to pass parameters ie
cmd /c start java "c:/vishal/runfile a b" where a and b are the parameters. but it is not accepting this in Runtime.getRuntime.exec(),
any solutions ?????????
regards,
Vishal -
hi all
i am looking for code to run a program(any EXE File ) from developer Form (Developer 6i)
thanks a lotlook at the documentation for the HOST command in Forms.
Regards
Grant Ronald
Forms Product Management -
How to run perl file from java file..???
Hi All,
How to run a perl file from java file.I know that there is one JPL(Java-Perl Library) preprocessor which can be used to do this,but no idea of how to do it..
Any help is appreciated.
Thanks in advance.viswa07 wrote:
Ok and any idea regarding JPL..????I don't know it and the first few posts that I found mentioned it using Java 1.1-style JNI calls, which hints at a dead project. And you don't want to use a dead project. -
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
-
How to run SQL files from Java?
Hi,
Can someone point me towards a link on how to run sql files in Java? Thanks.
P.S...if I've been completely blind please go easy on me!Sorry forgot the formating code thingy
public static boolean executeScript(File script, Connection conn){
boolean success = true;
success = script.exists();
if(success){
DEBUG.print("ES::READING SCRIPT:" + script.getAbsolutePath());
StringBuffer buffer = new StringBuffer();
success=readScript(script,buffer);
if(success){
try{
String creationScript = buffer.toString();
Statement st = conn.createStatement();
int start = 0;
int end = 0;
while (end != -1 && start < creationScript.length()) {
end = creationScript.indexOf("GO", start);
if (end != -1) {
DEBUG.print(creationScript.substring(start, end));
st.executeUpdate(creationScript.substring(start, end));
start = end + 2; //2 is the length of "GO"
st.close();
}catch(Exception e){
success=false;
DEBUG.printStackTrace(e);
}else{
DEBUG.print("ES::SCRIPT FILE DOES NOT EXISTS");
success=false;
return success;
public static boolean readScript(File script, StringBuffer buffer){
boolean success = true;
DEBUG.print("RS:: reading file :" + script.getAbsolutePath());
try{
InputStreamReader isr = new InputStreamReader(new FileInputStream(script),"UTF16");
int ch;
while ( (ch = isr.read()) > -1) {
buffer.append( (char) ch);
if (isr != null)
isr.close();
}catch(Exception e){
success=false;
DEBUG.printStackTrace(e);
return success;
}
Maybe you are looking for
-
How to limit max IMAP connections in mail.app?
Hi folks, due to Mailserver configuration limitations from Provider side like courier-imap settings "maxperip" = 4, some (like me) may have problems to use or connect more than one imap-account to the same server in mail.app. In thunderbird you have
-
Hello, I'm trying to figure out the proper way to detect the unloading of a loaded swf. My app is an AIR/iOS book project that behaves differently on the device vs testing locally in Flash Builder. When viewing the console in debug I see this in Flas
-
Flash player 11.7.700.224 keeps crashing in firefox 21.0
anybody else having trouble with flash player 11.7.700.224 crashing in firefox 21.0?
-
Hi! I will get a macbook pro bought in Canada soon. Can I use the adapter plug of my iphone (ireland) not the cable, as the adapter to plug my macbook? The power adpter of the macbook from Canada is a two pin. Thanks for any help.
-
My computer crashed while exporting and it won't let me open that catalog
My computer crashed while I was exporting photos and now it won't let me open that catalog. It says keeps telling me another application has that catalog open and I need to quit the other copy before it will open it. The problem is I don't know wha