글쓴이 :장태규 2000년 5월 10일 08:08:27
안녕하세요.
Java 프로그램에서 C program을 실행 시키려고 합니다. C program에서 scanf()를 사용하여 사용자로 부터 입력을 받으면 다음으로 넘어가게 하려고 하나 C program이 처음부터 멈춘상태에서 다음으로 넘어가지 않는 군요.
어떻게 하면 이문제를 해결 할 수 있는지 아시는 분 꼭 좀 알려주시면 고맙겠습니다.
program source code는 아래와 같습니다.
// Java Program
// Exec.java
import java.io.*;
public class Exec {
static public void main(String args[]) {
Runtime myRuntime = Runtime.getRuntime();
Process myProcess = null;
try{
myProcess = myRuntime.exec("abc"); // Execute abc 실행 file
/*
DataInputStream myInput =
new DataInputStream(new BufferedInputStream
(myProcess.getInputStream()));
*/
BufferedReader myInput =
new BufferedReader(new InputStreamReader
(myProcess.getInputStream()));
String buf = null;
while((buf=myInput.readLine()) != null)
System.out.println("From C"+ buf);
}catch(IOException e) {
System.out.println("JJJ"+ e.getMessage());
}
}
}
/* C program */
/* abc.c */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char name[128];
printf("Just came into abc.c\n");
printf("#Antony Bang\n");
printf("Enter your name\n");
scanf("%s", name);
printf("You entered %s\n", name);
printf("Just finished abc.c\n");
return (0);
}