September 28th, 2003, 04:18 PM
close && reopen stdout
any reason i shouldn't do this? or is there a better more portable way?
its works as expected:
puts("can u see me?");
puts("now can u see me?");
i actually have no idea what '/dev/pts/0' is, but the symbolic link from '/dev/fd/1' leads there. when i try to open '/dev/fd/1' i get a ENOENT error, so i tried this and it worked.
Last edited by infamous41md; September 28th, 2003 at 05:19 PM.
September 28th, 2003, 05:39 PM
Other than wasted CPU cycles I don't think there is any danger. Since you have closed the handle to stdin, I presume the OS just dumps the puts() into the bit bucket. Obviously it doesn't crash since you got it to run properly. Is there any reason why you want to do it this way or just hacking? As for being portable, I think you can do an fclose() on stdin (though I haven't tried it). What you would do to open stdin I have no idea. Lemme know if you find an ANSI way of doing this.
September 28th, 2003, 07:02 PM
heh yea its just laziness basically. i have this fairly large program that i would like to add a "quiet" mode to. after further thinking i realized a perl script that does a s///g on all of the printf's and substitute tests for all of them should do the trick, but the idea of just closing stdin was more fun(hackish) i guess :D and yes when it calls write() it just returns EBADF which isnt fatal.