[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] popen() and bufferevents



Hi,

I am using popen() to execute a program which will run for a few minutes and I want to be notified of any input coming in so I can write all that to a live log window. Just wondering: Is there anything stopping me from using bufferevents for this?

Even tho bufferevent seems to be more geared towards sockets I guess I could just use fileno(FILE*) and pass that onto bufferevent_new (which appears to be somewhat hidden, or well - I can't find it at http://monkey.org/~provos/libevent/doxygen-2.0.1/bufferevent_8h.html), right?

I'm asking because this is what I have implemented at the moment:

 if ((fp = popen(command, "r")))
 {
     int fd = fileno(fp);
     fcntl(fd, F_SETFL, O_NONBLOCK);

     bev = bufferevent_new(fd, &read_cb, NULL, &error_cb, NULL);
bufferevent_base_set(base, bev); // <- apparently there is no way to do this in one command yet?
     bufferevent_enable(bev, EV_READ);
 }

It however never calls my read callback, only the error callback with an EOF event once the program dies. I am suspecting that the program that I am running is not being nice. But before I start debugging that program I just want to verify that this is something that would be possible with bufferevents.

Is there any (other/recommended) way to do this?

Environment: Debian stable, libevent 2.0.8-rc

--
Bas
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.