Hi everyone , i am banging my head over the following problem for a couple of weeks now: i am starting a MyProg.exe(a simple C app) from a java class with .exec() as a system process(not in it's own console) and i would like to communikcate with its I/O before it is finished. I don't have this issue if for instance i am starting another java app.
The problem i meet is that the I/O is bloked while the process is being executed.When i terminate it , it is all released but it doesn't do me any good...
Here is some source , i'd really a ppreciate some help as i am stuck here....
[CODE=java] String[] command={"cmd", "/c","prog.exe "};
Runtime rt = Runtime.getRunt ime();
Process proc = rt.exec(command );
InputStream stderr = proc.getInputSt ream();
PrintWriter out = new PrintWriter(new OutputStreamWri ter(proc.getOut putStream()), true);
String str="123";
BufferedOutputS tream bufStr= (BufferedOutput Stream) proc.getOutputS tream();
bufStr.write(23 1);
bufStr.flush();
InputStreamRead er isr = new InputStreamRead er(stderr);
BufferedReader br = new BufferedReader( isr);
String line = null;
while ( (line = br.readLine()) != null)
System.out.prin tln(line);
int exitVal = proc.waitFor();
System.out.prin tln("Process exitValue: " + exitVal);
} catch (Throwable t)
{
t.printStackTra ce();
}
[/CODE]
the C prog i am running:
[CODE=c] #include <stdio.h>
#include <conio.h>
void main(void){
int i;
printf("sdfsdcd s");
scanf("%d",&i);
printf(" \n %d",i);
}[/CODE]
The problem i meet is that the I/O is bloked while the process is being executed.When i terminate it , it is all released but it doesn't do me any good...
Here is some source , i'd really a ppreciate some help as i am stuck here....
[CODE=java] String[] command={"cmd", "/c","prog.exe "};
Runtime rt = Runtime.getRunt ime();
Process proc = rt.exec(command );
InputStream stderr = proc.getInputSt ream();
PrintWriter out = new PrintWriter(new OutputStreamWri ter(proc.getOut putStream()), true);
String str="123";
BufferedOutputS tream bufStr= (BufferedOutput Stream) proc.getOutputS tream();
bufStr.write(23 1);
bufStr.flush();
InputStreamRead er isr = new InputStreamRead er(stderr);
BufferedReader br = new BufferedReader( isr);
String line = null;
while ( (line = br.readLine()) != null)
System.out.prin tln(line);
int exitVal = proc.waitFor();
System.out.prin tln("Process exitValue: " + exitVal);
} catch (Throwable t)
{
t.printStackTra ce();
}
[/CODE]
the C prog i am running:
[CODE=c] #include <stdio.h>
#include <conio.h>
void main(void){
int i;
printf("sdfsdcd s");
scanf("%d",&i);
printf(" \n %d",i);
}[/CODE]
Comment