D
druidamix
I'm trying to make a gui for an application, but it not run.
i'm trying to send the output of execlp to pipe and read from his
father. but i don't obtain results.
Any advince?
Thank you.
This is the code:
#include<gtk/gtk.h>
#include<glade/glade.h>
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdlib.h>
GladeXML *xml;
static void button_widget(GtkWidget *widget,gpointer data);
int main(int argc,char *argv[])
{
GtkWidget *button1;
GtkWidget *principal;
gtk_init(&argc,&argv);
xml = glade_xml_new("gtk.glade",NULL,NULL);
principal = glade_xml_get_widget(xml,"principal");
button1 = glade_xml_get_widget(xml,"boto1");
g_signal_connect(G_OBJECT(principal),"delete-event",
G_CALLBACK(gtk_main_quit),principal);
g_signal_connect(G_OBJECT(button1),"clicked",
G_CALLBACK(button_widget),NULL);
gtk_main();
return 0;
}
void button_widget(GtkWidget *widget,gpointer data)
{
//GtkWidget *textview;
//GtkWidget *entry;
//GtkTextBuffer *buffer;
//const gchar *text;
gint a[2];
gint pid;
gchar cbuffer[BUFSIZ+1];
memset(cbuffer,'\0',strlen(cbuffer));
if(pipe(a) ==0)
{
if((pid = fork()) ==0)
{
close(1);
dup(a[1]);
close(a[1]);
if(execlp("translate","translate","yes",NULL) == -1)
perror("No executat");
}
else
{
int i;
wait(&i);
close(a[1]);
close(0);
dup(a[0]);
close(a[0]);
if( (i= read(a[0],cbuffer,strlen(cbuffer))==0))
printf("Error\n");
printf("***%s hello",cbuffer);
}
}
}
i'm trying to send the output of execlp to pipe and read from his
father. but i don't obtain results.
Any advince?
Thank you.
This is the code:
#include<gtk/gtk.h>
#include<glade/glade.h>
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdlib.h>
GladeXML *xml;
static void button_widget(GtkWidget *widget,gpointer data);
int main(int argc,char *argv[])
{
GtkWidget *button1;
GtkWidget *principal;
gtk_init(&argc,&argv);
xml = glade_xml_new("gtk.glade",NULL,NULL);
principal = glade_xml_get_widget(xml,"principal");
button1 = glade_xml_get_widget(xml,"boto1");
g_signal_connect(G_OBJECT(principal),"delete-event",
G_CALLBACK(gtk_main_quit),principal);
g_signal_connect(G_OBJECT(button1),"clicked",
G_CALLBACK(button_widget),NULL);
gtk_main();
return 0;
}
void button_widget(GtkWidget *widget,gpointer data)
{
//GtkWidget *textview;
//GtkWidget *entry;
//GtkTextBuffer *buffer;
//const gchar *text;
gint a[2];
gint pid;
gchar cbuffer[BUFSIZ+1];
memset(cbuffer,'\0',strlen(cbuffer));
if(pipe(a) ==0)
{
if((pid = fork()) ==0)
{
close(1);
dup(a[1]);
close(a[1]);
if(execlp("translate","translate","yes",NULL) == -1)
perror("No executat");
}
else
{
int i;
wait(&i);
close(a[1]);
close(0);
dup(a[0]);
close(a[0]);
if( (i= read(a[0],cbuffer,strlen(cbuffer))==0))
printf("Error\n");
printf("***%s hello",cbuffer);
}
}
}