www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/06/28/07:16:17

Date: Tue, 28 Jun 1994 12:22:57 +0200
To: djgpp AT sun DOT soe DOT clarkson DOT edu
From: tony AT nt DOT tuwien DOT ac DOT at (Anton Helm)
Subject: Re: Redirecting gcc's messages

>On Fri, 24 Jun 1994, Peter Waszkewitz wrote:
>> Is there any possibility of redirecting gcc's messages to a file. I tried 
>> the standard method:
>>   gcc [whatever there is to do] > filename
>> but it didn't work.
>
>Gcc writes all its messages to standard error which cannot be 
>redirected under Command.com.

I use the following program to redirect stderr. It is available from some 
ftp servers (I dont know where I took it...)


/*
** redirect -- feed line to shell with stdin/stdout/stderr redirected
**
** usage -- redirect [-i newin] [-o newout] [-e newerr] command
**
** executes command via the shell, but redirects stdin/stdout/stderr first.
** stdout/stderr are appended, not overwritten.
*/

#include <stdio.h>

extern char *strcat( char *, char * );
extern char *strcpy( char *, char * );
extern int system( char * );
extern void exit( int );
extern int errno;
char umsg[] = "usage: redirect [-i newin] [-o newout] [-e newerr] command\n";
char emsg[] = "can't redirect %s to %s\n";

void main ( int, char ** );
void main ( argc, argv )
	int argc;
	char **argv;
	{
	int result;
	char buf[5120];

	argc--;  argv++;
	if (!argc) {
		fprintf( stderr, umsg );
		exit( 0 );
		}
	while (**argv == '-') {
		if (*(*argv+1) == 'i') {
			argc--;  argv++;
			if (!freopen( *argv, "r", stdin )) {
				fprintf( stderr, emsg, "stdin", *argv );
				exit( 1 );
				}
			}
		else if (*(*argv+1) == 'o') {
			argc--;  argv++;
			if (!freopen( *argv, "a", stdout )) {
				fprintf( stderr, emsg, "stdout", *argv );
				exit( 1 );
				}
			}
		else if (*(*argv+1) == 'e') {
			argc--;  argv++;
			if (!freopen( *argv, "a", stderr )) {
				fprintf( stderr, emsg, "stderr", *argv );
				exit( 1 );
				}
			}
		else
			fprintf( stderr, "unknown option %c\n", *(*argv+1) );
		argc--;  argv++;
		}
	if (!argc) {
		fprintf( stderr, umsg );
		exit( 0 );
		}
	strcpy( buf, *argv++ );
	while (*argv)
		strcat( strcat( buf, " " ), *argv++ );
	if (result = system( buf ))
		fprintf( stderr, "exit code = %d, errno = %d\n", result,
			errno );
	exit( 0 );
	}



Just compile...

Tony
============================================================================
Office:                           **    Private:
                                  **
Dipl.-Ing. Anton HELM             **
Institut fuer Nachrichtentechnik  **    
und Hochfrequenztechnik           **    Anton HELM
Guszhausstr. 25/389               **    Gratian-Marx Str. 7/27
A-1040 Wien                       **    A-1110 Wien
AUSTRIA                           **    AUSTRIA  
                                  **
Tel.: +43-1-58801-3520            **
FAX : +43-1-5870583               **
                                  **
email: Anton DOT Helm AT nt DOT tuwien DOT ac DOT at **
       tony AT nt DOT tuwien DOT ac DOT at       **
                                  **
============================================================================
   ________   __    __           __        __   __   _______   __        __
  /__   __/  / /   / /          / /       / /  / /  / _____/  /  \      / /
    /  /    / /   / /  _____   / /  __   / /  / /  / /____   / /\ \    / /
   /  /    / /   / /  /____/  / /  / /  / /  / /  / _____/  / /  \ \  / /
  /  /    / /___/ /          / /__/ /__/ /  / /  / /____   / /    \ \/ /
 /__/    /_______/          /___________/  /_/  /______/  /_/      \__/

============================================================================


- Raw text -


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