Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dos Command

Status
Not open for further replies.

Hattusas

Programmer
Nov 11, 2001
344
TR
Greetings everyone.
I am trying to obtain a result returned by an EXE program in DOS mode.
I activate the program by using appropriate java classes but couldn't manage to get the results produced by the EXE program.

Is it possible to get the values? If so how?

Thank you.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
If you post some code it will help. Are you using the Process object to run the exe? If so, you may be able to use the .exitValue method to get the return value. Alternatively, if the exe writes output that tells you the exit status, you may be able to use .getOutputStream to get that info.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
You could handle OS processes like this :

Code:
Process p = Runtime.getRuntime().exec("my.exe");
// make sure you wait for the exe process to exit
// get its exit status.
int exitStatus = p.waitFor();
if (exitStatus != 0) {
  BufferedReader br = new BufferedReader(new InputStreamReader(p.getErroStream()));
 // read the stream as usual to see if there was an error at stderr
 throw new Exception("OS exe process failed !");
} else {
  BufferedReader br = new BufferedReader(new InputStreamReader(p.InputStream()));
  // read the output from the process if any
}

--------------------------------------------------
Free Database Connection Pooling Software
 
I will try the exitValue and waitFor operations as you both suggested and inform you the results. Thanks for taking time for my problem.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
I tried the process but the BufferedReader could find nothing to read unfortunately.It returned null.
I do need the data printed on the dos screen but I wonder if there is a way besides Runtime.exec() and getting the InputStream.



Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
If the standard streams (stderr, stdout) are not picking up the output of the exe, then you have two options :

- try using Runtime.exec() to call a batch (.bat) file which then in turn calls the exe.

- Use the JNI to hook into the exe, but this will mean having access to the exe source code, and a lot of hassle, recompilation etc.

Other than that, there is no other way to interface with the OS.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top