stdout redirection

From: Nadav (Nadav_at_discussions.microsoft.com)
Date: 10/23/04


Date: Sat, 23 Oct 2004 03:49:01 -0700

Hi,

Introduction:
***************
I am trying to redirect stdout to a RichEdit control, this is done by
initiating a StringWriter, associated it with a StringBuilder and setting the
Console.Out to the String Writer, when ever the RichEdit is to be updated
text from the StringBuilder is being copied.

The Problem:
***************
What was just described works well as long as I am dealing with managed
code, my managed app loads some inproc unmanaged DLLs using PInvoke, these
DLLs are using printf*.* to write to the stdout, BUT when redirecting stdout
in the manner just described all of the data being printed by the unmanaged
app doesn’t show on the redirected console output.
I have tried redirecting the unmanaged code output in the following manner:
int fd = 0;
FILE *fp = 0;
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. ( internally
GetFileType doesn’t recognize the stdout handle returned by ‘GetStdHandle’ As
a valid file handle…

What should I do how can I redirect the unmanaged stdout to the same
destination as the managed stdout? I would expect the unmanaged code to
transparently write to the redirect stdout….

Any help would be appreciated.

-- 
Nadav
    http://www.ddevel.com


Relevant Pages

  • Re: Backgrounding a stream, and sendmail?
    ... >> just redirect the output to a file instead of sendmail.) ... > shell command like ... when prog_b has it's stdout redirected nothing ... > is done instead of printing to stdout you could start sendmail from within ...
    (comp.os.linux.development.apps)
  • stdout redirection
    ... I am trying to redirect stdout to a RichEdit control, ... text from the StringBuilder is being copied. ... DLLs are using printf*.* to write to the stdout, ...
    (microsoft.public.dotnet.languages.vc)
  • Redirecting STDOUT under ActivePerl on Windows XP
    ... I want to redirect STDOUT to a file, and have the redirection apply to ... any programs that I invoke. ... print "outer calling middle\n"; ...
    (comp.lang.perl.misc)
  • Re: Why wont exec work?
    ... eval exec $cmd 2>@ stdout ... Now you're redirecting stderr directly to stdout and no window pops up, ... Is there any way I can redirect stdout and stderr it so that it can ...
    (comp.lang.tcl)