The function is defined as follows:
File * freopen (const char * filename, const char * mode, file * stream );
In the Windows console, the standard output device is con. in Linux,/dev/tty is used to display the current terminal. The standard output device is/dev/console, but the individual test is only TTY.
To be successful. After Set-user-ID is set and the user is changed to root, the output still cannot be completed using the console. The specific reason remains to be verified.
In Windows:
# Include <stdio. h>
# Include <stdlib. h>
Int main (INT argc, char * agrv [])
{
Freopen (agrv [1], "W", stdout );
Printf ("What is going on? /N ");
Printf ("Good/N ");
Freopen ("con", "W", stdout );
Printf ("succeed! /N ");
Fclose (stdout );
Exit (0 );
}
In Linux:
# Include <stdio. h>
# Include <stdlib. h>
Int main (INT argc, char * agrv [])
{
Freopen (agrv [1], "W", stdout );
Printf ("What is going on? /N ");
Printf ("Good/N ");
Freopen ("/dev/tty", "W", stdout );
Printf ("succeed! /N ");
Fclose (stdout );
Exit (0 );
}