delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/19/17:03:31

Sender: <solyom AT bmeik DOT eik DOT bme DOT hu>
Date: Mon, 19 Dec 1994 17:38:16 +0100
From: "DR. SOLYOM ANDRAS" <solyom AT bmeik DOT eik DOT bme DOT hu>
Reply-To: SOLYOM AT HUBME51 DOT bitnet
To: babcock AT cfa DOT harvard DOT edu
Cc: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Subject: Re: output redirection in version 2

	> I've never seen them in source form
A while ago I have sent a little program to this list which redirects
stderr to stdin, but it somehow didn't made it. As the question seems
to be arise again, I give it another try. So here is the program:
**************** ERR2STD.C ********** CUT HERE *****************
#include <stdio.h>
#include <io.h>
#include <process.h>

main(int argc, char **argv)
{
        int nStdErr;

        if(argc < 2)
        {
                fprintf(stderr, "Error output redirection program for DOS\n"
                        " Usage: %s <executable name> [<parameters>]\n", argv[0
                exit(1);
        }

        dup2(fileno(stdout), fileno(stderr));
        argc--;
        argv++;

        execvp(argv[0], argv);
        perror("");
        return 0;
}
************** CUT TILL HERE ************************
This program was compiled by Turbo C++/Borland C++ and was tested 
to run correctly with GCC. (OK Do not tell me that I have an unused
variable nStdErr! FIrst I put some test printout in the program and
when I took them out I simply forgot to delete that line...)

I hope this helps.
				Andras

- Raw text -


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