By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

How send execlp result to the father?

P: n/a
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);

}

}

}

Jun 9 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In article <11**********************@q66g2000hsg.googlegroups .com>,
<dr*******@gmail.comwrote:
>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?
Your code uses many operating-system extensions that we are not
qualified to discuss here. This newsgroup pretty much only deals with
C as defined in the C standards, without any extensions. You should
ask in one of the comp.unix.* newsgroups.

>This is the code:
[OT]
> if((pid = fork()) ==0)
{
[...]
> if(execlp("translate","translate","yes",NULL) == -1)
perror("No executat");
}
> else
{
int i;
wait(&i);
I'm not up to speed on such things (ask in comp.unix.*) but
I believe wait() waits for the child process to die, not for the
child process to be ready. If the child process has already died,
then it isn't going to be able to talk to you.

Maybe something it wrote would be sitting in the buffers, but you
cannot count on that: what it wanted to write might have been too
large for the inter-process buffers to store (they are only about 4 Kb
or 8 Kb, something on that order), so the child process might have just
written a bit and then gotten suspended waiting for the parent to read
what was already written before the child could go ahead and write
more. So the child needs to be alive while processes are talking
(except perhaps during the -last- buffer-full), not having already died.

--
All is vanity. -- Ecclesiastes
Jun 9 '07 #2

P: n/a
dr*******@gmail.com wrote:
>
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.
.... snip ...
>
This is the code:

#include<gtk/gtk.h>
#include<glade/glade.h>
No such headers as the above two
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
No such headers as the above three
#include<stdlib.h>
In addition there is no such function as "execlp". Which may
explain your troubles. Either use standard C or go to a group that
deals with your system, whatever that may be.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com

Jun 9 '07 #3

P: n/a

<dr*******@gmail.comwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
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>
#include <assert.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];
assert(0);
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);

}

}

}
Add the modifications. That will tell you whether that function is being
called, and with any luck you OS will also allow you to ignore the assert(),
so you can step through it.

Next step is to try outputting a string to stderr or stdout. Do you have
output?

Once you've got that far, hack into the pipe() call to see if it doing what
you expect. Does it return at all? Does it return what you expect?

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Jun 9 '07 #4

P: n/a
dr*******@gmail.com writes:
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?
Ask in comp.unix.programmer. execlp is not a standard C function;
it's specific to Unix-like operating systems.

When you post there, you should be much more specific about the error
you're seeing. Saying you "don't obtain results" is not particularly
useful. You get *some* results, just not the ones you're expecting.
If the program does nothing and immediately terminates, say so. If it
does nothing and hangs, say so. If it produces any output or other
visible behavior, describe it.

But I do see at least one C problem in your code.

[...]
void button_widget(GtkWidget *widget,gpointer data)
{
[...]
gchar cbuffer[BUFSIZ+1];

memset(cbuffer,'\0',strlen(cbuffer));
[...]

You don't initialize cbuffer at the point of declaration. Since it
has automatic storage duration (i.e., it's declared inside a function
without the "static" keyword), its initial value is garbage.

You apply the strlen() function to cbuffer. strlen() scans the
*contents* of the array for a terminating '\0' character. It's likely
that it will happen to find one, but it's not guaranteed.

You need to understand the difference between a string and a character
array. A character array is a data type; an object of such a type has
a size determined by how it's declared. In your program cbuffer has a
size of BUFSIZE+1 (I'm assuming gchar is a character type). A string,
on the other hand, is a data *format*. Specifically (C99 7.1.1p1):

A string is a contiguous sequence of characters terminated by and
including the first null character.

An array object (such as cbuffer) doesn't hold a string until and
unless you store a string in it. The strlen() function can only be
applied to strings.

What exactly are you trying to accomplish with your memset() call?
If you want to zero the entire array, you should use sizeof:

memset(cbuffer, 0, sizeof cbuffer);

[...]
if( (i= read(a[0],cbuffer,strlen(cbuffer))==0))
printf("Error\n");

printf("***%s hello",cbuffer);
[...]

Again, you apply strlen to cbuffer. If you've successfully
zero-filled it, then strlen(cbuffer) yields 0; if you haven't,
strlen(cbuffer) is meaningless. Again, you probably want to use
sizeof, not strlen.

The read function isn't defined by the C standard. Any specific
questions about it belong in comp.unix.programmer. But assuming it's
similar to the standard C function fread, it reads data from an input
source into a specified buffer. If it succeeds, cbuffer *still* won't
contain a string unless you happened to read a '\0' character from the
input source (file, socket, whatever). printf's "%s" format works
only with strings, so your printf call is also likely to cause
problems.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 9 '07 #5

P: n/a
Malcolm McLean wrote:
>
.... snip ...
>
Add the modifications. That will tell you whether that function
is being called, and with any luck you OS will also allow you to
ignore the assert(), so you can step through it.

Next step is to try outputting a string to stderr or stdout. Do
you have output?

Once you've got that far, hack into the pipe() call to see if it
doing what you expect. Does it return at all? Does it return what
you expect?
Please do not answer off-topic requests here. There are (at least
in theory) no experts to correct mistakes. The appropriate
response is to redirect to a suitable newsgroup, if known, or to a
class of newsgroups if not. If the question cannot be resolved by
reference to a suitable C standard, it is off-topic.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 9 '07 #6

P: n/a

"CBFalconer" <cb********@yahoo.comwrote in message
news:46***************@yahoo.com...
Malcolm McLean wrote:
>>
... snip ...
>>
Add the modifications. That will tell you whether that function
is being called, and with any luck you OS will also allow you to
ignore the assert(), so you can step through it.

Next step is to try outputting a string to stderr or stdout. Do
you have output?

Once you've got that far, hack into the pipe() call to see if it
doing what you expect. Does it return at all? Does it return what
you expect?

Please do not answer off-topic requests here. There are (at least
in theory) no experts to correct mistakes. The appropriate
response is to redirect to a suitable newsgroup, if known, or to a
class of newsgroups if not. If the question cannot be resolved by
reference to a suitable C standard, it is off-topic.
I didn't mention the internals of the particular libraries the OP was
calling. I showed how to tackle the problem of bug hunting, using standard
library constructs.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 10 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.