delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/11/29/03:17:40

Date: Wed, 29 Nov 2000 10:15:55 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Anderson <ealmeida AT sigmanet DOT com DOT br>
cc: djgpp AT delorie DOT com
Subject: Re: How to switch popen read/write modes?
In-Reply-To: <3A243655.9539F8B@sigmanet.com.br>
Message-ID: <Pine.SUN.3.91.1001129101534.10519C-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 28 Nov 2000, Anderson wrote:

> I was trying to control a "child" program within a "parent" one, sending
> to it messages and reading it's output, without the user even noticing
> the existence of "child".

This cannot work in DJGPP because asynchronous subprocesses are not
supported.

What you need for your program is the ability to run a child program,
feed it some input, then have it stopped in its tracks and pass the
CPU control to the parent while the parent reads the output and feeds
it some more input.  Then you want control to return to the child
program again, so that it could process the additional input from
parent; etc.

This requires that that OS supports two programs (the parent and the
child) that are active at the same time.  DOS and DJGPP don't support
that.

The DJGPP implementation of popen suspends the parent program for the
entire time that the child program runs.  So you can feed the child
program some input, then read its output when the child exits and
control is passed back to the parent program.  But by that time, the
child program already exited, so there's no way of passing it more
input, except by invoking it again.

If you don't need that the child program ``remembers'' the results of
previous invocation(s), or if you can somehow restore the child
program's state which it was in at the end of the previous invocation,
you can write a program that invokes the child via popen each time you
have some input for it, then let it exit and read its output.
However, some programs, such as shells and debuggers, make this very
difficult, because they have lots of side effects attached to each
command they perform.

- Raw text -


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