www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/23/22:39:27

From: cziwkga AT ulcc DOT ac DOT uk (Kevin Ashley)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with popen()
Date: 23 Oct 1996 14:14:30 GMT
Organization: University of London Computer Centre
Lines: 46
Distribution: world
Message-ID: <54l986$k20@calypso.ulcc.ac.uk>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 961023094058 DOT 6813R-100000 AT is>
Reply-To: k DOT ashley AT ulcc DOT ac DOT uk
NNTP-Posting-Host: silver-e.ulcc.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <Pine DOT SUN DOT 3 DOT 91 DOT 961023094058 DOT 6813R-100000 AT is>, Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> writes:
|>
|>On Mon, 21 Oct 1996, Juanjo Erauskin wrote:
|>
|>>     "A stream opened by popen should be closed by pclose, which waits
|>> for the associated process to terminate and returns the exit status of
|>> the command. "
|>> 
|>> 	DJGPP pclose() function doesn't return exit status. Return 0 if 
|>> pclose is OK or return -1 if pclose doesn't terminate good.
|>
|>The question is: what does POSIX say about `pclose'?  DJ?

My copy of the POSIX spec has gone walkabout, but looking at
the man pages of 3 POSIX-compliant systems here they all agree
that what popen actually returns is the status that would be
returned by "waitpid" on the child. This is actually an encoded
version of the return status, and there are a set of defined macros
that extract various fields from it. That said, I don't believe POSIX
says anything about popen or pclose - they aren't part of its world.

|>
|>The diff you posted is incomplete, I think.  On MSDOS, when you call
|>`popen' to *read* from the pipe, the command is called by `popen', and
|>`pclose' just closes and deletes the temporary file used as the ``pipe''. 
|>So in that case, the exit status should be saved by `popen' to be returned
|>later by `pclose'. 
|>

I think you are right. The diff Juanjo posted was to popen:

|>> if ((retval = system (l1->command)) == EOF)

but it's not clear what's happening to retval. However, it is the
right status, since system() is defined to return the same wstat-encoded
return status as waitpid (and pclose). Whether or not the thing
is meaningful depends on what system() actually does return under
djgpp, and I don't have my machine to hand to check that with the
docs.
 
------------------------------------------------------------------------------
Kevin Ashley                              K DOT Ashley AT Ulcc DOT ac DOT uk
Development Manager             http://www.ulcc.ac.uk/staff/Kevin+Ashley
University of London Computer Centre.      ...ukc!ncdlab!K.Ashley
                      This is not a signature

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019