Trouble getting standard output in Java from a C program with getchar() -


i'm trying call c program java , capture standard output. here code:

try {     processbuilder pb = new processbuilder("helloworld.exe");     pb.redirecterrorstream(true);   // merge std out , std err same stream     program = pb.start();           // start program      bufferedreader input = new bufferedreader(new inputstreamreader(program.getinputstream()));      line = input.readline();     while (line != null) {         system.out.println(line);         line = input.readline();     }    } catch (ioexception e) {     e.printstacktrace(); } 

here sample c program:

int main(){     printf("hello world\n"); } 

this works fine when program i'm executing (helloworld in case) not have getchar() in it. however, if add getchar() right after printf, never off input stream. ideas why?

thanks

as kyle said, may need flush output stream after calling print make sure characters go standard output without delay. should in both programs. can done in c fflush(stdout); , can done in java system.out.flush().

--david


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -