delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/02/26/18:48:18

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Mon, 26 Feb 2007 18:48:06 -0500
Message-Id: <200702262348.l1QNm6a0007058@envy.delorie.com>
From: DJ Delorie <dj AT delorie DOT com>
To: Gordon DOT Schumacher AT seagate DOT com
CC: djgpp AT delorie DOT com
In-reply-to:
<OF2B682706 DOT 37B71AA3-ON8725728E DOT 00816B3A-8725728E DOT 00825322 AT seagate DOT com>
(Gordon DOT Schumacher AT seagate DOT com)
Subject: Re: pipe, spawn, and redirecting stdout for child process?
References: <OF2B682706 DOT 37B71AA3-ON8725728E DOT 00816B3A-8725728E DOT 00825322 AT seagate DOT com>
Errors-To: nobody AT delorie DOT com

> Is there a way in DJGPP to use the spawn*() functions and capture
> stdout of the spawned process via a pipe?  Is there an example of
> that somewhere?

Not with a pipe.  You have to dup2() the stdin/out/err descriptors to
temp files for the child program.

> I've tried looking at the source code to redir but I'm just not
> putting it together.

Consider this unix example:

$ prog1 > /tmp/foo.$$
$ prog2 < /tmp/foo.$$ > /tmp/bar.$$
$ prog3 < /tmp/bar.$$

This is the same as "prog1 | prog2 | prog3" but without pipes.

> Perhaps this is just a case of me not figuring out how to mesh the
> UNIX-ish way of doing it with the DOS-ish way... :-P I understand
> how to do it using fork but obviously that's not an option here.

Another option is to look at the pexecute module in gcc's libiberty,
which encapsulates all the different ways of running programs with
stdin/stdout/pipe stuff all hidden away.

- Raw text -


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