473,395 Members | 1,629 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,395 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 11299

"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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.