I write a simple C program, and build it to "AskStack.exe".
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
getchar();
return 0;
}
and then i use the java program to exec the C program, i want to get the output.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Test {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime().exec("AskStack.exe");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
do{
line = reader.readLine();
System.out.println(line);
}while(line != null);
p.waitFor();
}
}
but i failed. the java program did not output anything. i note that if i remove the getchar() of the C program, it will get the output. But my purpose is to interact with the C program.
So how should i modify my java code? thanks in advance.