473,769 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How send execlp result to the father?

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(G tkWidget *widget,gpointe r 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_w idget(xml,"prin cipal");
button1 = glade_xml_get_w idget(xml,"boto 1");

g_signal_connec t(G_OBJECT(prin cipal),"delete-event",
G_CALLBACK(gtk_ main_quit),prin cipal);
g_signal_connec t(G_OBJECT(butt on1),"clicked",
G_CALLBACK(butt on_widget),NULL );
gtk_main();
return 0;
}

void button_widget(G tkWidget *widget,gpointe r data)
{
//GtkWidget *textview;
//GtkWidget *entry;
//GtkTextBuffer *buffer;
//const gchar *text;
gint a[2];
gint pid;

gchar cbuffer[BUFSIZ+1];

memset(cbuffer, '\0',strlen(cbu ffer));

if(pipe(a) ==0)
{
if((pid = fork()) ==0)
{
close(1);
dup(a[1]);
close(a[1]);
if(execlp("tran slate","transla te","yes",NUL L) == -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
6 2460
In article <11************ **********@q66g 2000hsg.googleg roups.com>,
<dr*******@gmai l.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("tran slate","transla te","yes",NUL L) == -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
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.securityfoc us.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

<dr*******@gmai l.comwrote in message
news:11******** **************@ q66g2000hsg.goo glegroups.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(G tkWidget *widget,gpointe r 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_w idget(xml,"prin cipal");
button1 = glade_xml_get_w idget(xml,"boto 1");

g_signal_connec t(G_OBJECT(prin cipal),"delete-event",
G_CALLBACK(gtk_ main_quit),prin cipal);
g_signal_connec t(G_OBJECT(butt on1),"clicked",
G_CALLBACK(butt on_widget),NULL );
gtk_main();
return 0;
}

void button_widget(G tkWidget *widget,gpointe r 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(cbu ffer));

if(pipe(a) ==0)
{
if((pid = fork()) ==0)
{
close(1);
dup(a[1]);
close(a[1]);
if(execlp("tran slate","transla te","yes",NUL L) == -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
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.progr ammer. 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(G tkWidget *widget,gpointe r data)
{
[...]
gchar cbuffer[BUFSIZ+1];

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

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.progr ammer. 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_Keit h) 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
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.securityfoc us.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

"CBFalconer " <cb********@yah oo.comwrote in message
news:46******** *******@yahoo.c om...
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3583
by: Melissa Wallis | last post by:
In a Python script I start a number of C++ processes using os.execlp. Most of these processes output messages for debugging purposes at this time. The problem I am having is that by starting 4 or 5 processes from my Python script I don't get the cout messages they write. I have tried redirecting stdout to a file but I get everything but the output from the C++ processes. Any suggestions. Thanks Melissa
4
10042
by: Paul Nilsson | last post by:
Hi, Does anyone know how to redirect text output when issuing a system or an execlp call? I have a GUI that insists on opening up a console whenever I give a system function call, and I would like to redirect the text output to a char buffer instead. Paul
1
3255
by: Ralf | last post by:
Hi, I have 4 tables: "T_father1",...,"T_father4". In relation to these father-tables I have a child-table: "T_Child" (with only 1 foreignkey-field: FsID) alread filled with some records. That means each record of "T_Child" has in its field "FsID" a primary key of one of the 4 father tables. If I want to create the 4 foreign-key CONSTRAINTS:
6
5335
by: Erik S. Bartul | last post by:
as i understand if, the first argument of execlp() is a null terminated string containing the path of the command which to be executed. the second argument is an array of pointers to null terminated strings, containing the arguments to be passed to said command, ending in a null pointer. my question is, what does the third argument do?
6
2823
by: rabidmonkey | last post by:
Hi all, I have written a server & child program both are working fine but when the server tries to execute the child program with the line execlp("child","child", parameter, NULL ); nothing happens it does not call it, yet if I test the above line by substituting child with a system binary like pwd or ls it calls it without trouble. I have used the command "chmod a+x child" to make child executable but still to run child manually at the...
1
1445
by: kojy | last post by:
Hi, I have .ssi window with button that open new window like that: OpenWindow = window.open('LoginFDS.htm','FDSPassword','left=300,top=300,width=400,height=300,toolbar=0,resizable=0',directories=0,status=0,menubar=0); in the new window the user should enter password that should send to the .ssi window and close the new window. How can I send the password up to the .ssi page and then close the window. thanks
2
3254
by: manontheedge | last post by:
I'm trying to write a program in C on Linux where the child processes get their process images replaced. I have in my code, a few child processes that I forked from a single parent process. I'm then attempting to replace their ( the child ) process images with separate executables. I have these executables written and placed in the directory. My problem is when I'm using execlp. When it reaches execlp in my code, it does replace the...
7
1606
by: canajien | last post by:
How can I get a php page to automatically send all the contents in an email when it is generated? I managed to hack together a script that sends an email, but it will only send the 1st record returned and I would like it to send all the records that are on the page when it is loaded. <?php $con = mysql_connect("localhost","user","pass"); if (!$con)
1
2674
by: sunraj | last post by:
With the Following Fields can Anybody Help me, How do I send email from ASP using SMTP Authentication <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title></title>
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.