I have a dos program that I wish to access through my java program... I
can run the program and read the programs output using
DataInputStream in = new DataInputStream(new BufferedInputStream
process.getInputStream()));
But when I try to write to the program using...
DataOutputStream out = new DataOutputStream(new
BufferedOutputStream(process.getOutputStream()));
out.write(command.getBytes());
out.flush();
I get no response from the program and it doesn't seem to respond to
the command.
I am trying this on xp.
Lee Fesperman - 27 Jun 2005 01:49 GMT
> I have a dos program that I wish to access through my java program... I
> can run the program and read the programs output using
[quoted text clipped - 13 lines]
>
> I am trying this on xp.
You didn't show the contents of command. Perhaps the program needs a newline.

Signature
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
michael.shnitzer@gmail.com - 27 Jun 2005 03:18 GMT
It wasn't a new line problem... i tried new line and i have the flush
in there...
What is the correct way to use the getOutputStream of the process...
which is the stdin of the program opened by the process I assume.
Lee Fesperman - 27 Jun 2005 07:41 GMT
> It wasn't a new line problem... i tried new line and i have the flush
> in there...
>
> What is the correct way to use the getOutputStream of the process...
> which is the stdin of the program opened by the process I assume.
You need to do getOutputStream and getInputStream in separate threads. You may also need
to do getErrorStream (in yet another thread).
Have you tried writing a simple Java console application and calling that?

Signature
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
John Currier - 29 Jun 2005 04:45 GMT
> I get no response from the program and it doesn't seem to respond to
> the command.
What exactly do you mean by that statement? Does your program block
when it does a process.waitFor()?
If there's a chance that the program you're executing will send
anything to stdout or stderr then you'll need to create a thread to
read from the stream(s) that it's writing to (process.getInputStream()
/ process.getErrorStream()) as Lee mentioned. Note that if you don't
and if the program writes more data than the size of the output buffers
then the program will block waiting for someone to read from the other
side of those buffers...and nobody's there to read from it...deadlock.
John
http://schemaspy.sourceforge.net