Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Write to a process once its started using getOutputStream()

Reply
Thread Tools

Write to a process once its started using getOutputStream()

 
 
michael.shnitzer@gmail.com
Guest
Posts: n/a
 
      06-26-2005
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.

 
Reply With Quote
 
 
 
 
Lee Fesperman
Guest
Posts: n/a
 
      06-27-2005
wrote:
>
> 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.


You didn't show the contents of command. Perhaps the program needs a newline.

--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
 
Reply With Quote
 
 
 
 
michael.shnitzer@gmail.com
Guest
Posts: n/a
 
      06-27-2005
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.

 
Reply With Quote
 
Lee Fesperman
Guest
Posts: n/a
 
      06-27-2005
wrote:
>
> 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?

--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
 
Reply With Quote
 
John Currier
Guest
Posts: n/a
 
      06-29-2005
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Process.Start... started process not executing any code jpock76 ASP .Net 0 08-23-2010 02:16 PM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 14 04-03-2010 10:08 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 0 04-01-2010 10:25 PM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM
Getting process id of started process Joe Van Dyk Ruby 6 04-02-2005 02:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57