Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Oct 1998 10:12:57 -0600 (MDT)
From:      Darren Whittaker <djw@sage1.sagecorp.com>
To:        Mike Smith <mike@smith.net.au>
Cc:        freebsd-current@FreeBSD.ORG, john.young@openmarket.com
Subject:   Re: problem in 3.0 
Message-ID:  <Pine.SOL.3.93.981014101158.9432A-100000@sage1.sagecorp.com>
In-Reply-To: <199810141601.JAA01049@dingo.cdrom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
The fact of the matter is that date only returned output once, why did it
not return output 10 times?


-Darren
------------------
Darren Whittaker
Senior Software Engineer
Small Enterprise Group
Open Market, Inc.

On Wed, 14 Oct 1998, Mike Smith wrote:

> > Thank you for your email. I have taken your code and modified it to run as
> > a cgi:
> > 
> > #include <stdio.h>
> > #include <err.h>
> > #include <errno.h>
> > 
> > int main(int argc, char *argv[])
> > {
> >   int     i, j;
> >   char    buf[256];
> >   FILE    *p;
> > 
> > /* output the head */
> >   printf("Content-type: text/html\n");
> >   fflush(stdout);
> >   printf("\n<html><head><title>TESTING</title></head>");
> >   printf("<CENTER><H1>TESTING</CENTER></H1><HR>\n");
> >   printf("<body bgcolor=#ffffff><p><pre>\n");
> >   fflush(stdout);
> > 
> > /* loop using popen */
> >   for (i = 0; i < 10; i++)
> >   {
> >      buf[0] = '\0';
> >      if ((p = popen("/bin/date", "r")) == NULL)
> >      {
> >        printf("popen error: %s\n",strerror(errno));
> >        continue;
> >      }
> >      fgets(buf, sizeof(buf) - 1, p);
> >      printf(buf);
> > 
> >      if ((j = pclose(p)) != 0)
> >        printf("pclose error: %s [%d]\n",strerror(j),j);
> 
> This is incorrect; it should read
> 
>       if (pclose(p) == -1)
>         printf("pclose error: %s [%d]\n", strerror(errno), errno);
> 
> See the manpage for pclose().
> 
> > Here is some of the output when I run it from the web browser:
> > 
> > Wed Oct 14 07:00:13 PDT 1998
> > pclose error: No child processes [10]
> ...
> > What do you think the problem might be?
> 
> A return value of 10 from pclose() is not an error; it's the exit code 
> of the child process.  /bin/date does not appear to reliably set its 
> exit code.
> 
> -- 
> \\  Sometimes you're ahead,       \\  Mike Smith
> \\  sometimes you're behind.      \\  mike@smith.net.au
> \\  The race is long, and in the  \\  msmith@freebsd.org
> \\  end it's only with yourself.  \\  msmith@cdrom.com
> 
> 
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SOL.3.93.981014101158.9432A-100000>