Mail Archives: djgpp/1999/04/06/12:22:02
The Beyonder wrote:
>
> In DJGPP how can I pipe stderr or stdout to a file like foo.dmp? I
> assumed something like:
> // code...
> stdout = fopen( "foo.dmp", "wt" );
> // code..
>
> but DJGPP gives me:
>
> non-something lvalue....
Do you mean: "invalid lvalue in assignment"?
If you want help, it's a good idea to take the extra three seconds to
write down the correct error message.
Use freopen().
#include <stdio.h>
#include <stdlib.h>
const char *logname = "foo.dmp";
int main( void )
{
char cmd[128];
/* Reassign "stderr" to logname */
if (!freopen( logname, "w", stderr )) {
fprintf( stdout, "Error on freopen\n" );
return 1;
}
fprintf( stderr, "Something for the logfile\n" );
fclose( stderr );
fprintf( stdout, "Finished executing: dumping %s\n", logname );
sprintf( cmd, "type %s", logname );
system( cmd );
return 0;
}
--
########################################################################
Michael Smith emmenjay AT zip DOT com DOT au
Emmenjay Consulting Pty Ltd http://www.zip.com.au/~emmenjay/
Computers *ARE* user-friendly. You just need to be properly introduced.
- Raw text -