The Artima Developer Community
Sponsored Link

Java Answers Forum
Runtime.process.exec()

2 replies on 1 page. Most recent reply: Mar 6, 2002 12:54 PM by Aarti Thorat

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Aarti Thorat

Posts: 3
Nickname: at
Registered: Mar, 2002

Runtime.process.exec() Posted: Mar 5, 2002 5:12 PM
Reply to this message Reply
Advertisement
Hi,

I posted a question sometime ago, but didnt get an answer hence am posting my core confusion.

I wonder Runtime.exec() can deal with user interaction
in subprocess. For example, program A calls program B
through Runtime.exec(). Program B gives some output and
receives standard input. I understand how B's output is
redirected to A, but I have no idea how B's standard
input(terminal input) can be handled. When I tried this
type of program, I found out two processes just
wait(maybe blocked) forever.

hope to get some input,
thanks!


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Runtime.process.exec() Posted: Mar 6, 2002 12:27 AM
Reply to this message Reply
Well I assume your program B is trying to read user input from the standard input? If so, the problem is that program B's stdin is also hooked up to A (the program that called B with Runtime.exec().) A can get ahold of B's stdin by invoking Process.getOutputStream(). Can you perhaps let A grab input from the user and then pass it to B?

Aarti Thorat

Posts: 3
Nickname: at
Registered: Mar, 2002

Re: Runtime.process.exec() Posted: Mar 6, 2002 12:54 PM
Reply to this message Reply
Thanks for the input.
I did try this but the process behaves a little strangely than I expected or probably I am making a mistake somewhere. Here's the piece of code which does this.

InputStream prin = process.getInputStream();
BufferedReader bin = new BufferedReader(new InputStreamReader(prin));
String temp = bin.readLine();
System.out.println("the process output" + temp);
System.out.println("its trying to hook the input for B from A ");
OutputStream prout = process.getOutputStream();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
System.out.println("taken input ");
byte[] sb = s.getBytes();
prout.write(sb);
prout.flush();

this code is put in a loop till process completes execution.

While executing this code I found out that the program executing this code just blocks.

Hope to get some input from you again.
Thanks!
Aarti.

Flat View: This topic has 2 replies on 1 page
Topic: Comparable Class (overiding) Previous Topic   Next Topic Topic: Computer Name using Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use