所以我有这个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,它似乎是做你想做的事,试试吧 –