Re: stdout redirection

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: William DePalo [MVP VC++] (willd.no.spam_at_mvps.org)
Date: 10/23/04

  • Next message: William F. Kinsley: "Re: MC++ Unmanaged MFC calling Managed WinForm class"
    Date: Sat, 23 Oct 2004 12:00:16 -0400
    
    

    "Nadav" <Nadav@discussions.microsoft.com> wrote in message
    news:37582031-D696-4C6F-94C8-05A2C047F7A3@microsoft.com...
    > I am trying to redirect stdout to a RichEdit control, this is done by
    > ...
    > fd = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_APPEND);
    > fp = _fdopen(fd,"w");
    > *stdout = *fp;
    > setvbuf(stdout, NULL, _IONBF, 0);
    > But apparently it doesn't work: '_open_osfhandle' returns -1.

    I resort to this redirection technique when I need to add more debug trace
    capability than is convenient with OutputDebugString().

    _If_ I recall correctly, when you redirect the standard output device of a
    console application, any output you do in the main module _or_ in a DLL gets
    redirected properly.

    However, if you AllocConsole() in a windowed application and redirect
    standard output to it, then the redirection works _only_ in the main module.
    Any DLL loaded by the executable still "thinks" that it does not have a
    standard output device because the executable image was not marked as a
    console application when the DLL's runtime was initialized.

    So, my _guess_ is that you need to pass the device handle of the console to
    whatever executable component is redirecting output and redirect its
    standard output as well. Of course, I might be wrong.

    Regards,
    Will


  • Next message: William F. Kinsley: "Re: MC++ Unmanaged MFC calling Managed WinForm class"

    Relevant Pages

    • redirection of standard output of a Python command to a Python variable
      ... I try to find a quick way to redirect the standard output of a Python ... foobar = fsock.read ...
      (comp.lang.python)
    • Re: Redirecting output
      ... > want to redirect the standard output of printk to my xterm. ... The text comes out on modprobe's standard output. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Redirection output for a program in background
      ... But since it's started at boot, I have no access to the output that's ... to redirect the standard output on the fly to a terminal ... I did think of a similar solution, ie writing a script ...
      (comp.os.linux.misc)
    • Re: stdout redirection
      ... And how can I get a handle to a managed stream associated with the console? ... How can I get the handle to the redirected stream of a managed StringWriter? ... >> I am trying to redirect stdout to a RichEdit control, ... > standard output as well. ...
      (microsoft.public.dotnet.languages.vc)
    • Re: Redirection output for a program in background
      ... with pipes and greater-thans and so on. ... But since it's started at boot, I have no access to the output that's ... to redirect the standard output on the fly to a terminal ...
      (comp.os.linux.misc)