Sam Trenholme's webpage
This article was posted to the Usenet group alt.hackers in 1995; any technical information is probably outdated.

Re: File I/O hack...


Article: 7686 of alt.hackers
From: subbarao@myroom.Stanford.EDU (Kartik Subbarao)
Newsgroups: alt.hackers
Subject: Re: File I/O hack...
Date: 20 Apr 1995 00:08:22 GMT
Organization: putchar('I'); for (i = 0; i < 3; i++) putchar('E');
Lines: 13
Approved: root@internet.org
Distribution: world
Message-ID: 3n48lm$oj8@nntp.Stanford.EDU
NNTP-Posting-Host: myroom.stanford.edu
Status: RO

In article <3n3hcl$1if@csugrad.cs.vt.edu>,
The Root of All Evil <dmescher@csugrad.cs.vt.edu> wrote:
>Problem:  Wanted to redirect output to a file from the middle of a program,
>   and then go to stdout or the file at will w/o using fprintf.  Dup
>   er dup() and dup2() weren't working.
>Solution: Rip apart stdio.h and examine the FILE type.  To do redirection
>   (under UNIX), modify the _file field of stdout to whatever the
>   _file field of the output file is.  Doesn't work when the OS
>   redirects stdout, though.  Any suggestions?

Better solution: check out freopen(). /dev/tty points to your terminal.

    -Kartik



Parent

Back to index