Console screen buffer corrupts from other console application RRS feed

  • Question

  • I'm writing console application (app1), which starts another console application (app2) in the same console window.
    Then, app1 periodically reads console output of app2, till app2 is not terminated.
    This works fine, until app2 not used CreateConsoleScreenBuffer & SetConsoleActiveScreenBuffer functions.
    Example of such applications (app2) is telnet.exe, wich started without arguments.

    To read output from changed screen buffer (changed from other application), I use
    HANDLE h = CreateFile(L"CONOUT$",...).
    This work fine,
    But in Window 7 first call in app1 of CloseHandle(h) destroys screen buffer, created in app2
    // CreateFile and CloseHandle are called from app1

    sample program with sources:
    How to reproduce:
    1. RunConApp.exe c:\windows\system32\telnet.exe
    2. Press "OK" in message box "Press OK to start application"
    3. After telnet starts, and "Welcome to Microsoft Telnet Client" appers in the console, Press "OK" in message box "Press OK to Open&Close"
    4. Oops. Console screen buffer, created by telnet, is destroyed :( Sometimes (x86 version in x64 OS) console window is not redrawn, but minimize/restore updates it

    It's look like a bug in Windows 7 console realization?
    Monday, December 28, 2009 11:43 PM