Execute a .exe from a Java program
How can i execute a program though Java (e.g. the program could be a scandisk or disk defragmenter or paint etc.)
Is there a possibility to do that?
Yes, Runtime.getRuntime().exec(). this is for java 1.4.*
and this is for java 1.5Process p = new ProcessBuilder("path_To_EXE").start();
Similar Messages
-
How to start java.exe from a java program in windows ?
Hi,
I did like to know, if its possible to run java.exe from a java program on windows ? The java.exe should be visible from checking the processes that are currently running using the Task Manager on windows.Runtime.getRuntime().exec("java Sample");
-
Need to execute tcl script from a Java Program
Hello,
I need to execute a tcl script from a Java Program. But I do not know how to call the tcl Interpreter. Can anybody help me?Iam using the exec command as follows:
Process proc =
rt.exec("C:/SpirentConnect/engines/tcl/8.3.4/windows/s
ctcl.exe C:/Hello.tcl");
But Hello.tcl is not executed.And does that exact string work on the command line?
And what is the return code from running it? -
How to execute unix command from the Java program running on Windows
Hello,
I need to
1. Execute a unix shell script from a Java program running on the Windows.
2. I also need to capture the output of this shell script in my program.
Please suggest me how to achieve this.
Thanks in Advance.Hi...
Something is missing here
If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
You can test this using telnet tool on windows
just type on command prompt
telnet <ip of the unix pc> <port number this case 23>
you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant -
How:Execute OS commands from a Java program
hi,
is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
thanxIn the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results. -
Executing another exe from a java class
Hi All,
I want to execute another executable from a java class. I am doing that with the help of Runtime.getRuntime().exec(String) function.
My executable runs for quite sometime and it keeps printing something to stdout consistently.
I want to read whatever this exe is putting out to stdout as and when it is put out, not after the whole process has finished.
Now, Runtime.getRuntime().exec(String) just spawns the exe in another process space and I am not able to get its handle, maybe I have missed something.
Is there any other method/way to do what I want to?
TIA
-SatishNow, Runtime.getRuntime().exec(String) just spawns the
exe in another process space and I am not able to get
its handle, maybe I have missed something.
Is there any other method/way to do what I want to?Acutally, Runtime.getRuntime().exec(String) returns a Process object. Use this process to "talk" to the program you just launched. For your needs, try Process.getOutputStream(). Take a look at the API for Process at http://java.sun.com/j2se/1.3/docs/api/java/lang/Process.html
Hope this helps. -
Executing cgi-bin from a java program
I am trying to develop a Java HTTP server that also includes support for CGI-BIN but the last weeks i am stack at the same point ! I am trying to execute the cgi and then give it an argument but i never have an output ! Please help cause the deadline is coming near !!!
//Set environment variables
String[] setVar = {"REQUEST_METHOD=POST","CONTENT_LENGTH="+extra.length};
String[] cgi = {"/bin/bash","./home/pap/jhttp"+Petition_Analysis.pt.uri.path,"/n"};
//Execute the cgi-bin with the appropriate input
Process cgiOut = Runtime.getRuntime().exec(cgi,setVar);
// get its output (your input) stream
DataOutputStream put = new DataOutputStream(cgiOut.getOutputStream());
put.writeBytes(Petition_Analysis.pt.Pet_Body);
DataInputStream in = new DataInputStream(cgiOut.getInputStream());
// Read and print the output
String line;
StringBuffer page = new StringBuffer();
while ((line = in.readLine()) != null) {
page.append(line);
//Send page to client
out.print("HTTP/1.1 200 OK\r\n");
out.print("Content-Length: " + page.toString().length() +"\r\n\r\n");
System.out.print(page);
Cgi call is like that:
./post_from.cgi
first_operand=342&second_operand=32&operation=-
Note that there is a blank line !Well no, the script works perfectly, here is the output of the console in Linux system and this exactly what i want to do in the program:
[pap@laptop pap]$ export CONTENT_LENGTH=11
[pap@laptop pap]$ export REQUEST_METHOD=POST
[pap@laptop pap]$ /home/pap/jhttp/cgi-bin/post_form.cgi
op1=1&op2=2
Content-Type: text/html
<html><head><title>Script results</title></head>
<body>
<p>Number of sent fields: 2</p>
<p>
<b>Field:</b> op1<br>
<b>Valor:</b> 1
</p>
<p>
<b>Field:</b> op2<br>
<b>Valor:</b> 2
</p>
</body></html>
So the question is how to this inside a Java program and better forget my code which is erroneous
also forgive my english :) -
How to launch executable from a java program
In c++ we can use a function WinExec to execute exe from a c++ program.
Is there a way to launch executables using java program. Lets say I have one executable with name "myexecutable.exe" and a java program "myprogram.java". How can I launch "myexecutable.exe" from the java program.
Is there a way to do this in Java?
Vijay>>
class LoadExecutable
static void loadProcess()
Runtime r = Runtime.getRuntime();
Process p = r.exex("winword.exe");
public static void main(String args[])
loadProcess();
}Regards
- ManikantanBoth of these aren't good ideas - neither of them
deals with the input or output streams at all.
Everyone who's posted to this thread should read this.
None of you knows how to use Runtime.exec properly:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-t
aps.html
MOD
Thanks for the tips
-Regards
Manikantan -
How can I pass system commands from a java program? Urgent!
hi,
I have been trying this out since a long time. How do I send system commands to command.com or cmd.exe from a java program and an output of the executed command back to the java application.
If u have any idea, or have any information about the kind os application reply back.
Thanks
Deepa DatarThis is the code which I tried, but it displays only the title of MS-DOS, something like " Microsoft Corp...etc ". But doesn't take any input, and the subprocess(cmd.exe) hangs.
import java.io.*;
public class cmddemo2
public static void main(String arg[])
try
System.out.println("cmd");
Process p=Runtime.getRuntime().exec("cmd.exe");
DataInputStream din=new DataInputStream(p.getInputStream());
DataOutputStream dout=new DataOutputStream(p.getOutputStream());
System.out.println("after streams");
String s;
dout.writeChars("type cmddemo2.java");
while((s=din.readLine())!="\n")
System.out.println(s);
dout.writeChars("dir");
String s1;
while((s1=din.readLine())!="\n")
System.out.println(s1);
System.out.println("over");
catch(Exception e)
{ System.out.println("Exception : "+e); -
Calling another application from a java program
Hi, Java ppl.
I wanted to know how can I call another program say a help application or an exe from a java program. anyone with any advice or a piece of code would help.
Thanks
PradeepI had the same situation and I tried the code that you sugested and it works. I was wondering, what am I expecting in the while loop that appears after the int inp; statement? Is some data going to be displayed on the screen? How essential is to have that while loop after the calling the exec() method?
Sorry for the amount of questions, I never tried this before.
Best regards,
Luis E. -
How can I execute a batch file from my java program
Hi,
Can someone help me or direct me to a link,
How can I execute a DOS batch file from my java program?
ThanksYou will need to grab a handle to the process's
outputstream so u can see its output.The OP didn't mention any output from any batch file;
nor any input for that
matter,so lets not complicate matters here for now
ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
I'm sure it wasn't intentional that your post appeared to be bristling with attitude. -
How to start an executable program from a java program ?
Hi,
does someone know how to start an executable program from a JAVA program ?
Thanks, Fred.Take a look at the Runtime class.
-S- -
Execute several UNIX OS commands from inside Java program
Greetings,
I would like to be able to execute from a Java program several of the following UNIX commands
script filename
cd
date
grep
diff
I have been able to get a single command to work with
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("dir");
My goal here is to accomplish a Java program which will use JDBC to access an Oracle database with SQL and then compare the resultant flat file with a diff command in Unix to another delimited file from an Excel spreadsheet. Your input is appreciated.
Thank youI would suggeat to use JDBC to get the data from database and then read your file and then use existing java diff program from following link to find the differences between the files
http://www.bmsi.com/java/
I hope this helps
VAN -
Executing a stored procedure from a java program
Hi.. how can i call a oracle stored procedure from a java
program. the OSP has four IN parameters and one OUT parameter(a
cursor). when i try this way.. i get an error
con = DriverManager.getConnection(url, "stored", "stored");
CallableStatement cs =
con.prepareCall(
"{call stored_proce_1(?,?,?,?,?)}");
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.setString(2, "14541");
cs.setString(3, "gen");
cs.setInt(4, 0);
cs.setInt(5, 5);
ResultSet rs =cs.getResultSet();
while(rs.next()){
System.out.println(rs);
appreciate ur help.
qsI'm no expert on this, but I have a similar call where I fetch
an Oracle REF CURSOR from a call to a stored function. If you
fetch the cursor as an Object from your CallableStatement, you
can then cast it to a ResultSet e.g.
mystatement.executeUpdate();
ResultSet rs = (ResultSet) mystatement.getObject(1);
Then you should be able to loop through your ResultSet as usual.
Good luck!
Chris -
Calling an executable from a java program
How can I call a compiled program from a java program. I have a fortran program, which I would like to call for execution from within my java program. My OS is linux.
Thanks,
AnNot quite sure in the case of fortran program, but one thing can be done, call ur fortran program from a batch (.bat file) and call this .bat file from java ;
try {
Process p = Runtime.getRuntime().exec("run.bat");
p.waitFor();
catch( Exception e ) {
}
Maybe you are looking for
-
Can't log into iTunes store account
So I can no longer log into my iTunes store account. When I try to log in, I get an error message in red letters saying: FieldName: null. java.lang.Exception I have tried resetting my password mutliple times with no luck. I can log into my Apple Stor
-
Is there any upragde tools for SAP B1 to SAP ERP?
Hi, I know, SAP B1 and SAP ERP are totally different SAP products. In my mind, maybe we should implement the new SAP ERP, and then, migrate the old master data from B1 to ERP... So, is there any upragde tools or procedure (or data migration tools)for
-
ITunes 11.0.1 window size issue
The window size on my copy of iTunes 11.0.1 has stretched beyond the bottom of the screen. I am no longer able to resize the window except in width. This came about when I lowered the window until only the top of the menu bar was exposed at the bot
-
User cannot connect to SCCM 2012 R2 CAS site from any location
I have a strange issue happening with only one of my users. No matter where he attempts to connect from, his console session gets hung up at "Connecting to Site Database". He is the only one of my users having this issue and was able to connect up t
-
When addressing an email, Thunderbird used to provide a list of options almost instantly. Now it takes several seconds and stops accepting more than three or four characters until it has finished the first search. Then it works on the next few charac