Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!ficc!peter From: peter@ficc.ferranti.com (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: redirecting output Message-ID: Date: 1 Jul 90 23:52:01 GMT References: <22931@dartvax.Dartmouth.EDU> <1990Jun29.172429.2818@zoo.toronto.edu> Reply-To: peter@ficc.ferranti.com (Peter da Silva) Organization: Xenix Support, FICC Lines: 21 In article <1990Jun29.172429.2818@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: > You have the right idea, but you left something out. Try this instead: While picking nits, how about doing it right. There's really no excuse for not calling perror: > #define FILENAME "filename" > if (freopen(FILENAME, "w", stdout) == NULL) { + perror(FILENAME); ! fprintf(stderr, "Can't re-open standard output -- exiting\n"); > exit(1); > } > God is not on your side; such a call *will* fail eventually. Life is > much more pleasant if your code copes properly. And life is even better if it tells you *why* it fails. If your C runtime doesn't implement perror, make it. I don't know of any operating system where you can't at least differentiate between missing files and other errors. Well, outside the top levels of the orange book, anyway. -- Peter da Silva. `-_-' +1 713 274 5180.