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