On 2001.01.15 19:29:25 +0100 Timothy M. Shead wrote:
> Ronald Bultje wrote:
> 
> > For a simple application, I use the call:
> > 
> > system("a_command");
> > 
> > this runs this application. Now, this application needs some simple
> user
> > input ("press enter to do this", etc). I tried creating a second thread
> to
> > do this, but this will not press enter for this thread but for its own.
> So
> > the a_command programm still thinks enter wasn't pressed.
> > Can someone think of a way to give this user input without having to do
> it
> > console by hand? (I mean, I try to make a GUI! :) )
> > 
> 
> Don't use "system" to run the external program - use "popen" instead, 
> which returns a set of pipes you can use in your main application to 
> write to the child's stdin and read from its stdout.
> 
> If I recall correctly, the one caveat to this technique is that the 
> child process won't work if it's got an X UI of its own - check the GTK+ 
> FAQ for the complete scoop.
> 
> Regards,
> Timothy M. Shead
> 
> 
> 
> 

I have tried it yesterday.... The application dumps core directly at
startup, I probably am doing something wrong. What? By the way, it compiles
fine....
The code below here is made from pieces of info I found on websites, so
there might be a basic mistake in it.... I am just learning c++, am not
that experienced yet....
The piece of code that applies to this pipe is below:

#include <stdio.h>
[....]
FILE *pipe;
[....]
void emulate_enter()
{
//      system("\r");
        fprintf(pipe, "\r");
}

void *create_control_window()
{
        GtkWidget *window, *button;

        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title (GTK_WINDOW (window), "Capturing Window");
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);

        button = gtk_button_new_with_label("[Enter]");
        gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(emulate_enter), NULL);
        gtk_container_add(GTK_CONTAINER(window), button);
        gtk_widget_show(button);
        gtk_widget_show (window);
}

void write_result(GtkWidget *widget, gpointer data)
{
[....]
        //command->str is a char with a certain command, the command itself
        //depends on user input as well...
        pipe = popen(command->str, "w");
        if (pipe == NULL)
        {
                g_print("Error during opening pipe...");
                pclose(pipe);
        }
        else
        {
                create_control_window();
        }
}
[....]


_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to