How does one pipe output from process to text buffer?



Hello,

I need some example code or a tutorial for how to pipe output from a
process to a GtkTextBuffer.

The idea of this program is to spawn off 6 or more ssh commands and have
the output go to it's own textbuffer in it's assigned notebook page.

This is what I have so far.  Now I need the output from the process to
go to it's respective text buffer.


void on_confirm_okbutton_clicked (GtkWidget *widget, gpointer data)
{
        /* ****************************************
         * Globals used:
         *      serverlist : string array of server names
         *      command    : the options to send to mainscript program
         *      notebook1  : notebook widget
         */
        
        gchar *tmp_ssh_command;
        gchar **ssh_command;
        gint i = 0;
        gint count = g_strv_length(serverlist);
                        
        /* remove any existing notebook pages */
        remove_notebook_pages(GTK_NOTEBOOK(notebook1));
        
        /* start a process for each server */
        for (i=0; i<count; i++ ) {
                tmp_ssh_command=g_strjoin(" ", SSH_PROGRAM, serverlist[i],
MAINSCRIPT_PROGRAM, command, NULL);
                ssh_command = g_strsplit(tmp_ssh_command, " ", -1);
                
                /* CREATE NOTEBOOK PAGE FOR THIS PROCESS */
                
                /* create textview */
                GtkWidget *textview;
                GtkWidget *scroller;
                GtkTextBuffer *buffer = gtk_text_buffer_new(NULL);
                GtkWidget *label = gtk_label_new(serverlist[i]);
                gchar *introtext = g_strdup_printf("WORKING ON: %s\n%s\n",
serverlist[i], tmp_ssh_command);
                textview = gtk_text_view_new_with_buffer(buffer);
                gtk_text_buffer_set_text(buffer, introtext, -1);
                g_free(introtext);
                g_free(tmp_ssh_command);
                gtk_widget_show(textview);
                
                /* create scrolled window for textview */
                scroller = gtk_scrolled_window_new(NULL, NULL);
                gtk_scrolled_window_set_policy(
                                GTK_SCROLLED_WINDOW(scroller),
                                GTK_POLICY_AUTOMATIC,
                                GTK_POLICY_NEVER);
                gtk_widget_show(scroller);
                gtk_container_add(GTK_CONTAINER(scroller), textview);
                
                /* finally create the notebook page */
                gtk_notebook_insert_page(
                        GTK_NOTEBOOK(notebook1), 
                        scroller, label, i);
                
                /* now fire off the process and redirect output
                 * to our textbuffer */
                GPid pid;
                g_spawn_async_with_pipes( NULL,
                                          ssh_command, 
                                          NULL, 
                                          G_SPAWN_CHILD_INHERITS_STDIN,
                                          NULL,
                                          NULL,
                                          &pid,
                                          NULL, NULL, NULL,
                                          NULL );
        }
        
        gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook1), 0);
        
        gtk_widget_show(progressdialog);
        gtk_widget_hide(confirmdialog);
}

Any help, pointers, tips would be appreciated :-)

-- Tony





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