The Artima Developer Community
Sponsored Link

Java Answers Forum
java.lang.process.exec() and I/O.

0 replies on 1 page.

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 0 replies on 1 page
Aarti Thorat

Posts: 3
Nickname: at
Registered: Mar, 2002

java.lang.process.exec() and I/O. Posted: Mar 5, 2002 1:46 PM
Reply to this message Reply
Advertisement
Hi,

I am executing a class file through a thread using the Runtime.getruntime.process.exec() call. The executing class file is blocked indefinitely as it needs some input from the console. I am attaching the code where ExeClass class contains code to execute the class file and this object is instantiated in Filter class.
The output of the executing class file is obtained through getInputStream() method but I do not know how to give input to the executing class file.

Can anybody gimme any idea on this ?

Here's the code.
----------------------------------------
import java.lang.StringBuffer.*;
import java.io.*;

public class Filter{

public static void main(String[] args) {

Filter f = new Filter();

System.out.println("just before starting to execute the class");

Execlass ec = new Execlass();
ec.start();
}
}

class Execlass extends Thread{

public void run(){
Process execClass;
DataOutputStream usrinput;
BufferedInputStream pgmoutput;
BufferedInputStream pgmerroutput;

try{
Runtime rt = Runtime.getRuntime();
System.out.println("executing the class file st in execlass");
String cmd = new String("java ");
cmd = cmd + Filter.classname;
execClass = rt.exec(cmd);

try{
pgmerroutput = new
BufferedInputStream(execClass.getErrorStream());
usrinput = new DataOutputStream(execClass.getOutputStream());
pgmoutput = new BufferedInputStream(execClass.getInputStream());
System.out.println("executing in execlass");
}
catch(Exception e){
System.out.println("exception occured" +e);
}

}
catch(Exception e1){
System.out.println("exception occured" +e1);
}
}
}
---------------------------------------------------

thanks !

Topic: classes Previous Topic   Next Topic Topic: Help with Java comm API

Sponsored Links



Google
  Web Artima.com   

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