Re: stdout/sterr to GtkTextView at runtime



On 11.12.2015 06:14, orangensaftx web de wrote:
I'm writing a gui for an existing program that can run for a while. I
want to display all possible terminal output of this program in a
GtkTextView. So far i failed to display the output at runtime. I tried this

The simple and straightforward answer is: launch your application by opening a perl file for piping output from the target application into an input channel of your Gtk3 perl script- see http://perldoc.perl.org/functions/open.html.

But this is not very satisfactory: your GUI becomes blocked while the application is running. If you want to run your GUI target program in background and continue working interactively with the GUI (i.e. your Gtk programme) while your target application does its work, you should make your file-handle non-blocking and use Glib::IO->add_watch to attach a signal that handles events from your I/O channel: this allows to aynchronously handle input from your target application (typically: copy lines to your textview panel).

You can still do better: use open2 or open3 rather than plain open in support of an additional channel, adding the possibility of sending data from the GUI to the target application and to distinguish between stdout and stderr - allowing to reply to queries, or even implementing a dialog. De-facto this allows to conceive your GUI with parallelism between the GUI and the target-application (the parallelism is supported via callback procedures attached to the I/O signals).

I just saw the reply from Jeffrey Ratcliffe - sending this nevertheless, it practically is a comment on the logic of the code attached by Jeffrey

Juergen


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