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); }