473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

pclose: returning termination status of command

Stu
I am running a simple c program on Solaris 2.8 that calls a ksh shell
script x which contains an exit statement of 58 (exit 58).
cat xxx.c

#include <stdio.h>
#include <errno.h>

int
main()
{

FILE *ptr;

char buf[BUFSIZ];
char *cmd="./x";

if ((ptr = popen(cmd, "r")) != NULL)
{
while (fgets(buf, BUFSIZ, ptr) != NULL)
(void) printf("%s", buf);

printf("\nProcess returned %d\n", pclose(ptr));

}
return 0;
}

cat x
#!/bin/ksh
exit 58
When I run the C program I get the following:
../xxx
Process returned 14848

I would have expected to see 58. Can anybody tell me why I am getting
14848.

man pclose
RETURN VALUES
The pclose() function returns the termination status of the
command. It returns -1 if stream is not associated with a
popen() command and sets errno to indicate the error.

Thanks in advance for all that answer this post
Jul 22 '05 #1
2 11301

"Stu" <be********@hotmail.com> wrote in message
news:a4**************************@posting.google.c om...
I am running a simple c program on Solaris 2.8 that calls a ksh shell
script x which contains an exit statement of 58 (exit 58).
cat xxx.c

#include <stdio.h>
#include <errno.h>

int
main()
{

FILE *ptr;

char buf[BUFSIZ];
char *cmd="./x";

if ((ptr = popen(cmd, "r")) != NULL)
{
while (fgets(buf, BUFSIZ, ptr) != NULL)
(void) printf("%s", buf);

printf("\nProcess returned %d\n", pclose(ptr));

}
return 0;
}

cat x
#!/bin/ksh
exit 58
When I run the C program I get the following:
./xxx
Process returned 14848

I would have expected to see 58. Can anybody tell me why I am getting
14848.

man pclose
RETURN VALUES
The pclose() function returns the termination status of the
command. It returns -1 if stream is not associated with a
popen() command and sets errno to indicate the error.

Thanks in advance for all that answer this post


This post asks about running a C program from a shell script on a Solaris
platform, none of which are at all related to the topic of this newsgroup,
which is the use of the standard C++ language. Try in a newsgroup related
to one of those topics. You might also check your doc's or header files (or
use google) to see if 14848 is a known error code in your system.

-Howard

Jul 22 '05 #2
be********@hotmail.com (Stu) wrote in message news:<a4**************************@posting.google. com>...
I am running a simple c program on Solaris 2.8 that calls a ksh shell
script x which contains an exit statement of 58 (exit 58).
cat xxx.c

#include <stdio.h>
#include <errno.h>

int
main()
{

FILE *ptr;

char buf[BUFSIZ];
char *cmd="./x";

if ((ptr = popen(cmd, "r")) != NULL)
{
while (fgets(buf, BUFSIZ, ptr) != NULL)
(void) printf("%s", buf);

printf("\nProcess returned %d\n", pclose(ptr));

}
return 0;
}

cat x
#!/bin/ksh
exit 58
When I run the C program I get the following:
./xxx
Process returned 14848

I would have expected to see 58. Can anybody tell me why I am getting
14848.

man pclose
RETURN VALUES
The pclose() function returns the termination status of the
command. It returns -1 if stream is not associated with a
popen() command and sets errno to indicate the error.

Thanks in advance for all that answer this post


The returnvalue of the child process is in the top 16 bits. You have
to divide the returned value of pclose by 256, then you get the
searched return value of the child process.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Galt | last post by:
I am writing a rudimentary shell. The (idealized) code is like this: /* read_cmd returns argv */ char **read_cmd(); shell() { char **cmd; while {
8
by: tshad | last post by:
I have class method that is passing back a boolean, but it always returns a false; The class is: *************************************************************************** public bool Delete()...
3
by: Sean Tynan | last post by:
I want to find out the best way for a method to notify calling code of situations such as validation errors, etc. that may occur during method execution. e.g. say I have a method (business...
9
by: ehabaziz2001 | last post by:
I am facing that error message with no idea WHY the reason ? "Abnormal program termination" E:\programs\c_lang\iti01\tc201\ch06\ownarr01o01 Enter a number : 25 More numbers (y/n)? y...
3
by: Ralf Assmann | last post by:
Hi there, we have the following problem using a DB2 version 7 on z/OS, referring also <a...
8
by: Michal Nazarewicz | last post by:
Hi, What does returning 0 from main() mean according to C89/C90 standard? I've found that in C99 it means successful termination (7.20.4.3p5) however as I'm editing book on C at Polish Wikibooks...
1
by: Flyzone | last post by:
I need to run a network program and return output in a variable name without use temporany file. So i tought to use popen (i'm using python 2.3, i can't upgrade). RESULT = os.popen('command'+HOST,...
13
by: Logan Lee | last post by:
Hi. I've written a small program to learn to write in C. But unfortunately the output is all jumbled up and not nice. /* read_file.c The whole point of this code is to read the entire content...
0
by: NotepadZ | last post by:
I am getting a frustrating error when i try to insert into the table the trigger i created is on. Any insight would be appreciated Error: db2 => INSERT INTO trstat VALUES ('340758A', ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.