Thread: SDL redirects stdout/cout, can't output to con

  1. #1
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110

    SDL redirects stdout/cout, can't output to con

    Code:
    	con = fopen("CON", "w");
    	if (!con) {
    		printf("Cannot open CON\n");
    	}
    That bit of code (after SDL_init()) causes Cannot open CON to be printed to stdout.txt ratrher than pointing a valid pointer to CON (DOS console, which I want). Even redirecting:

    Code:
    	freopen( "CON", "w", stdout );
    	freopen( "CON", "w", stderr );
    doesn't fix the problem as stdout and stderr now don't work at all.

    (Note: SDL_init() redirects stdout and stderr to txt files). I've even tried using cout to find that it has the same problem.

    I'm using borland 5.5, SDL 1.2 and windows XP SP2.
    Last edited by Dark Nemesis; 03-19-2005 at 12:15 AM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Do the calls to freopen succeed? Perhaps you could specify the platform and OS and cite the usage of "CON" on this platform with regard to f[re]open? What are the contents of the file "CON"?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    1) They return 0
    2) CON is the console redirecting to the 'file' CON redirects to the console.
    3) See above.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    If there is no console, you will need to call AllocConsole(). This will create a new console window, and it will automatically initialize stdin, stdout, and stderr handles for the new console. These handles than then be retreived by calling GetStdHandle().

    If there is a console already, then I'm not sure as freopen should work the way you have it.

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    I think there are pre-compiled binaries that allow this. There is also another way that I can't remember (I don't think its worth troubling over personally). Try searching www.gamedev.net boards, thats where I saw it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  2. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  3. why this output?
    By dredre in forum C Programming
    Replies: 4
    Last Post: 05-08-2004, 04:09 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. Control different DA output value!
    By Hunterhunter in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-13-2003, 12:11 PM