www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/18/22:37:44

Date: Sun, 18 Dec 94 19:59:20 -0500
From: dj AT stealth DOT ctron DOT com (DJ Delorie)
To: mfeldman AT seas DOT gwu DOT edu
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: output redirection in version 2

If you have a PROGRAM calling something, and you want to trap stderr,
use dup2 and close/open to change the stderr file descriptor to a
file, then after the call, use close/dup2/close to move stderr back.
Something like this (no guarantees on accuracy):

	save_stderr = dup(2);
	dup2(new_stderr, 2);
	system();
	close(2); close(new_stderr);
	dup2(save_stderr, 2);
	close(save_stderr);


- Raw text -


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