On Mon, 16 Nov 2015 23:08:46 +0000, opla wrote: > Does anyone know if it's possible to monitor the events that happen on > the output stream of a piped process ? > > I'm stuck on doc: > > - https://www.win.tue.nl/~aeb/linux/lk/lk-12.html - > http://www.ibm.com/developerworks/library/l-ubuntu-inotify/ > - http://linux.die.net/man/2/inotify_add_watch > > inotify_add_watch second argument seems to be a file name. The only > thing available is a std.stdio.File with a handle. > > The goal is to create an asynchronous process with a least one > notification that would happen when the process terminates, maybe when > the output stream is written too.
You can use poll on the file descriptor (which can be gotten with File.fileno). Basically something like this (untested): while (ImWaiting) { if (processPipes.stdout.eof) { // The child is done writing (has exited, generally speaking) } //TODO set up poll items pollfd pfd = { processPipes.stdout.fileno, POLLIN }; // Use 0 for timeout so that we don't wait; if you don't have anything else // to do, you can use a real timeout value if (1 == poll(&pfd, 1, 0)) { // New data is available on the child's stdout, do something with it } // Do other things, sleep, etc. }