From owner-freebsd-current Wed Oct 14 08:57:58 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA11542 for freebsd-current-outgoing; Wed, 14 Oct 1998 08:57:58 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from dingo.cdrom.com (dingo.cdrom.com [204.216.28.145]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA11524 for ; Wed, 14 Oct 1998 08:57:52 -0700 (PDT) (envelope-from mike@dingo.cdrom.com) Received: from dingo.cdrom.com (localhost.cdrom.com [127.0.0.1]) by dingo.cdrom.com (8.9.1/8.8.8) with ESMTP id JAA01049; Wed, 14 Oct 1998 09:01:30 -0700 (PDT) (envelope-from mike@dingo.cdrom.com) Message-Id: <199810141601.JAA01049@dingo.cdrom.com> X-Mailer: exmh version 2.0.2 2/24/98 To: Darren Whittaker cc: Mike Smith , freebsd-current@FreeBSD.ORG, john.young@openmarket.com Subject: Re: problem in 3.0 In-reply-to: Your message of "Wed, 14 Oct 1998 08:12:03 MDT." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 14 Oct 1998 09:01:30 -0700 From: Mike Smith Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Thank you for your email. I have taken your code and modified it to run as > a cgi: > > #include > #include > #include > > 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("\nTESTING"); > printf("

TESTING


\n"); > printf("

\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