Re: Calling system() from a GTK+ callback



Thanks for the quick response.
I accidentally hit the "send" button when starting to compose this
reply, so disregard the previous message.

You're quite correct about my misplaced quote mark.  That's what
comes from composing the message without the code in front
of me ;)

I probably should have specified that the callback is from a menu
item produced with a structure declared as:
static GtkItemFactoryEntry menu_items[] =
{
.
.
 { "/Control/Initialize/start", NULL,  Start_Cmd, 0, NULL },
.
.
};

The menubar is initialized as follows:
/*++++++++++++++++++++++++++++++++++++++++++++++++++++
 +
 + Purpose:
 + The get_main_menu( GtkWidget *window, GtkWidget **menubar )
 + function builds the main menu by calling the gtk_item_factory_new
 + with an input of GTK_TYPE_MENU_BAR.
 +
 + The inputs to this function are the primary window and a
 + pointer to the Menu Bar.
 +
 +++++++++++++++++++++++++++++++++++++++++++++++++++++*/

   void get_main_menu ( GtkWidget *window, GtkWidget **menubar )
   /* This function builds the main menu by calling the gtk_item_factor
      with an input of GTK_TYPE_MENU_BAR. The inputs are explained below
      just prior to the call. The inputs to this function are the EPIU
      primary window and a pointer to the Menu Bar. */
   {
      GtkItemFactory *item_factory;
      GtkAccelGroup *accel_group;
      gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);

      accel_group = gtk_accel_group_new ();

      /* This function initializes the item factory.
         Param 1: The type of menu - can be GTK_TYPE_MENU_BAR,
         GTK_TYPE_MENU, or GTK_TYPE_OPTION_MENU.
         Param 2: The path of the menu.
         Param 3: A pointer to a gtk_accel_group.  The item factory
                  sets up the accelerator table while generating menus.*/

      item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
         accel_group);

   /* This function generates the menu items. Pass the item factory,
      the number of items in the array, the array itself, and any
      callback data for the the menu items.*/
      gtk_item_factory_create_items (item_factory,
         nmenu_items, menu_items, NULL);

   /* Attach the new accelerator group to the window. */
      gtk_accel_group_attach (accel_group, GTK_OBJECT (window));

      if (menubar)
      {
      /* Return the actual menu bar created by the item factory. */
         *menubar = gtk_item_factory_get_widget
            (item_factory, "<main>");
      }
   } /* End get_main_menu */


----- Original Message -----
From: "Gary Wong" <gtw research att com>
To: "David C. Hoos, Sr." <david c hoos sr ada95 com>
Cc: "GTK List" <gtk-list gnome org>
Sent: Thursday, October 19, 2000 1:44 PM
Subject: Re: Calling system() from a GTK+ callback


> "David C. Hoos, Sr." <david c hoos sr ada95 com> writes:
> > I am trying to issue a call of the form
> >
> >   system ("/usr/bin/rsh some-host 'some-command with arguments' >
> >       <some-file-on-remote-host &");
>
> Note that if you want the redirection to occur on the remote host, you
> should quote the redirection, as well (i.e. "rsh host 'cmd > foo' &", not
> "rsh host 'cmd' > foo &".  But that's an rsh issue, not a GTK one.
>
> > The command works when issued from a simple C program (not a GTK+
> > program), but the call "hangs" if made from a GTK+ callback function.
>
> I am unable to duplicate the problem.  The following test code appears to
> work for me (using either system() or fork()/exec()).  Note that the style
> is poor (it doesn't check return codes of system calls, nor clean up its
> zombies) but those things should be irrelevant to any GTK problems.
>
> Does my code work on your system?  If so, are you able to send me a small
> section of your code which does not work, or modify my example to
> demonstrate the problem?
>
> Cheers,
> Gary.
>
> ---------- example code follows:
> /*
>  * example of system() or fork()/exec() in a GTK+ callback
>  *
>  *    compile with "cc -o foo `gtk-config --libs --cflags` foo.c"
>  */
> #include <gtk/gtk.h>
>
> static void callback( GtkWidget *widget, gpointer data ) {
>
> #if 0
>     system( "rsh other-host 'date >> /tmp/abc' &" );
> #else
>     if( !fork() ) {
>         execlp( "rsh", "rsh", "other-host", "date >> /tmp/abc", NULL );
>         _exit( 1 );
>     }
> #endif
> }
>
> int main( int argc, char *argv[] ) {
>
>     GtkWidget *window;
>     GtkWidget *button;
>     GtkWidget *box1;
>
>     gtk_init (&argc, &argv);
>     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>     gtk_signal_connect (GTK_OBJECT (window), "delete_event",
>                         GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
>     box1 = gtk_hbox_new(FALSE, 0);
>     gtk_container_add (GTK_CONTAINER (window), box1);
>     button = gtk_button_new_with_label ("rsh");
>     gtk_signal_connect (GTK_OBJECT (button), "clicked",
>                         GTK_SIGNAL_FUNC (callback), NULL);
>     gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 20);
>     gtk_widget_show_all(window);
>     gtk_main ();
>     return(0);
> }
> --
>   Gary Wong    Consultant, Dependable Distributed Computing, AT&T Shannon
Labs
>         gtw research att com            http://www.cs.arizona.edu/~gary/
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list





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