473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

How to execute dos commands in java ???

i need to execute a .jar file in command line using java... n i have to take the output obtained from tat file...
Dec 23 '06 #1
1 17523
horace1
1,510 Expert 1GB
i need to execute a .jar file in command line using java... n i have to take the output obtained from tat file...
you can use the exec() method from RunTime, e.g.
Expand|Select|Wrap|Line Numbers
  1. // execute a child process using java exec command and get output
  2.  
  3. import java.io.*;
  4. import java.lang.*;
  5.  
  6. public class JavaExec {
  7.  
  8. public static void main (String args[]){
  9.   try {
  10.      // get runtime environment and execute child process
  11.      Runtime systemShell = Runtime.getRuntime();
  12.      Process output = systemShell.exec("java -jar hello.jar");
  13.      // open reader to get output from process
  14.      BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
  15.      String line = null;
  16.      System.out.println("<OUTPUT/>");
  17.       while((line = br.readLine()) != null ) 
  18.          { System.out.println(line);  }          // display process output
  19.      System.out.println("</OUTPUT>");
  20.      int exitVal = output.waitFor();             // get process exit value
  21.      System.out.println("Process Exit Value : "+ exitVal);
  22.      }
  23.    catch (IOException ioe){ System.err.println(ioe); }
  24.    catch (Throwable t) { t.printStackTrace();}
  25. }
  26. }
  27.  
Dec 23 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lance | last post by:
Hi All, I would like to read commands from a file and execute them in VB, something like reading str = "hello world" into VB and execute it. Any suggestions will be appreciated. Thanks, Lance
13
by: BlackHawke | last post by:
Our program, game program Andromeda Online (www.andromedaonline.net) uses two programs- one to play the game, another to patch the game as updates come out. Players actually launch the updater...
15
by: Madhanmohan S | last post by:
Hi All, I want to run a command line appplication from C#. When i start the application, it will go into specific mode. After that, i have to give commands to use the application. How Can This Be...
1
by: Faraz | last post by:
Hey guys. How cam I interface with the environment in C#. I want to execute commands in a (separate) process, just like java Runtime.exec(string command) does. Thanks in advance,
5
by: Good Man | last post by:
Hi there I am trying to execute a custom-built java program on my linux server via PHP. Basically, a user uploads files via PHP, and then the java program performs some action on these files. ...
14
by: technocrat | last post by:
db2 -t -v -f/home.../filename >output_file-name I have a java stored procedure..which has to run the above command...not sure how i can run this command through java.. any suggestions are...
1
by: janaki112 | last post by:
i want to convert a perl program to java.... for that i want to know how to execute more than one command in dos mode using java without going to tat dos prompt... for eg.. load english rules......
2
by: rcook349 | last post by:
I'm trying to automate our builds and publishes of our Windows application (deployed to a website via ClickOnce). I'm getting close, I think, on the commands I need to execute. However, how do...
5
by: sayeo87 | last post by:
Hi, I am quite new to JSP so please forgive me if I ask really simple things... I am trying to run system commands on the server and display the output on a webpage. This is what I've got: <%@...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.