Reading from a pipe without blocking the execution


I’m writing a GUI that basically controls the execution of other programs. I’ve used TSystem::OpenPipe to execute the program. Then, I read the pipe with TString::Gets and display it in the GUI with TGListBox::AddLine. Everything is simple and works very well, however, if the program running does not write a newline, the Gets method keeps waiting for it forever and blocks the execution of the program.

Is there a way to avoid this problem? Is there something like a signal that I can connect to a method of my GUI class that is raised when the pipe is ready to be read? If there is, how is this implemented in ROOT?




TString::Gets() uses fgets() internally which does what you describe. You could simply call fgetc() yourself and add the characters to the TString.

Cheers, Axel.

Hi Axel,

Thanks for your reply. That partially solves my problem.

However, let’s say that the program is not filling the buffer at all, for instance, a simple “sleep” command. The GUI execution also halts.

I was looking for something as I described before, or even, simpler, a version of fgetc or fgets with a timeout. Does that exist?

Thanks again.


okay, this is going a bit away from ROOT and more to generic C / C++… Google is usually pretty helpful with that. It shows e.g.

Cheers, Axel.

Thanks again Axel and sorry for the off-topic thread.

Very interesting this select() function, it’s all I needed and I ended up learning something new.