|
Replies:
7
-
Last Post:
Aug 25, 2008 8:16 AM
by: walterln
|
Threads:
[
Previous
|
Next
]
|
|
|
|
|
|
Redirection of DOS IO in Java
Posted:
Aug 8, 2008 5:43 AM
|
|
|
Hi all,
I have had the misfortune of being assigned a task which revolves around creating a Swing GUI for a DOS application. Obviously I would need to get access to the output of the underlying DOS app and I would also need to send data to the app.
At present I launch the app using ProcessBuilder.start(). Since it is a DOS app, you would have absolutely no idea that it is in fact running, unless you were to look in the task manager. If you run the app from the command line (cmd.exe) however, you are able to see its output in command prompt's window. Likewise, you are also able to give it textual input while it is running inside of cmd.exe.
At first I thought it would simply be a matter of printing the contents of process.getInputStream() but that was not to be. Indeed, running myDosApp.exe >> outFile on the command line itself results in an empty outFile.
If anyone has any idea about how to access the DOS IO streams, please let me know.
(I can live without accessing the output of my DOS app, but it is absolutely essential that I'm able to send data to it)
regards, Pierre
|
|
|
|
|
|
|
Re: Redirection of DOS IO in Java
Posted:
Aug 18, 2008 1:38 AM
in response to: irond13
|
|
|
Hmm... In the deeper recesses of my mind, I recall someone having trouble with this as well because DOS has four default streams: stdin, stderr, stdout, and a more obscure console that cannot be redirected through normal means. I could be grossly mistaken, though.
To rule out the obvious, have you tried reading from the error stream as well?
Cheers, Jonathan
|
|
|
|
|
|
|
|
Re: Redirection of DOS IO in Java
Posted:
Aug 18, 2008 6:25 AM
in response to: tarbo
|
|
|
Hi,
thanks for the thoughts. I actually haven't tried reading from stderr, but I'll give it a go. Logically though, stderr wouldn't be the main outputstream of any app.
Regards, Pierre
|
|
|
|
|
|
|
|
Re: Redirection of DOS IO in Java
Posted:
Aug 25, 2008 5:18 AM
in response to: irond13
|
|
|
You're confusing the Java InputStream with the DOS programs input stream. Process#getInputStream() gives you an InputStream in Java (from which you can read the programs output).
Since you want to write to the input of the DOS program, you need Process#getOutputStream() (you output data to the process). From the javadoc: Gets the output stream of the subprocess. Output to the stream is piped into the standard input stream of the process represented by this Process object.
|
|
|
|
|
|
|
|
Re: Redirection of DOS IO in Java
Posted:
Aug 25, 2008 7:17 AM
in response to: walterln
|
|
|
Hi,
perhaps I made myself unclear. I am aware that all the getStream methods of Process return streams relative to the java app and not to the Process instance itself.
Regards, Pierre
|
|
|
|
|
|
|
|
Re: Redirection of DOS IO in Java
Posted:
Aug 25, 2008 8:16 AM
in response to: irond13
|
|
|
I misread it then. Perhaps When Runtime.exec() won't contains a useful hint for you.
|
|
|
|
|
|
|
|
Re: Redirection of DOS IO in Java
Posted:
Aug 19, 2008 12:54 AM
in response to: irond13
|
|
|
> ProcessBuilder.start(). Since it is a DOS app, you > would have absolutely no idea that it is in fact > running, unless you were to look in the task manager.
If it is running within Windows then there are various command-line utilities that will give you information about running tasks. For instance on Vista you can use the TASKLIST command to list tasks. You can invoke such commands using Runtime.exec and then read the console output to obtain the results.
|
|
|
|
|
|
|
|
Re: Redirection of DOS IO in Java
Posted:
Aug 19, 2008 6:00 AM
in response to: luano
|
|
|
Hi Luan,
thanks for the input. The fact that the application runs in the background is not actually a problem. The problem is that I'm unable to access the IO streams of the app. Specifically I need access to what I would've thought would be its stdin.
Regards, Pierre
|
|
|
|
|