所以我有這個Java程序創建在終端上運行某個C程序的進程(unix),並且當C程序發生某些事情時(在終止之前)我需要通知Java程序)。我怎樣才能做到這一點?我知道我會需要信號,但我對這個主題沒有太多經驗。發送信號從C到Java
在此先感謝!
編輯:這是我對Java所做的更改,調用過程後:
InputStream stdout = p.getInputStream();
InputStreamReader isr = new InputStreamReader(stdout);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<INPUT>");
while ((line = br.readLine()) != null)
System.out.println(line);
System.out.println("</INPUT>");
int exitVal = p.waitFor();
System.out.println("Process exitValue: " + exitVal);
我什麼我,當我想通知的Java的C所做的:
char buff[20];
size_t nbytes;
ssize_t bytes_written;
int fd;
strcpy(buf, "This is a test\n");
nbytes = strlen(buf);
bytes_written = write(1, buff, nbytes);
但運行後我只能得到:
INPUT
/INPUT
Process exitValue: 0
使用此http://stackoverflow.com/questions/13904318/reading-作爲一個例子的a-substring-from-a-string-value,它似乎是做你想做的事,試試吧 –