Re: Calling system() from a GTK+ callback



----- 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]