Re: How to get stdout/stderr from unmanaged DLL?



Not necessarily, I just mean in a non-interactive way. Actually what I'm
trying to do is the following. I have a WindowsService which responds to
specific IPC commands by starting a utility application. It is this utility
application for which I want to get stdout redirected to a log file.

Reassigning my own TextWriter via Console.SetOut and Console.SetError *does*
correctly route all Console.WriteLine and Console.Error.WriteLine type of
calls from my managed code despite the fact that the app is running without a
console window. But any output from PInvoked calls to these unmanaged DLLs
is lost. I ensure that a Console exists for my application (via
AllocConsole) but this doesn't have any effect.

I know I could redirect to a temp file on the process startup from my
service and then get all output after the fact, but then I would lose the
sequence of output between console output from the managed code and unmanaged
DLL output.

-- Tom

"William Stacey [MVP]" wrote:

> Hi Thomas. What do you mean by "batch" mode without a window? Calling your
> c# console app from a batch file?
>
> --
> William Stacey [MVP]
>
> "Thomas W. Brown" <thomas_w_brown@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:00AE1384-18C6-4357-B51E-7448FFAA9316@xxxxxxxxxxxxxxxx
> >I have setup Console redirection within my Console app (via Console.SetOut
> > and Console.SetErrror) to route console WriteLine calls to a logfile.
> > This
> > works just fine with one exception...
> >
> > I use PInvoke to call into several unmanaged DLLs which write diagnostic
> > information out to stdout (and possibly stderr). When I run in a
> > "standalone" mode with no redirection, these DLLs do generate output to
> > the
> > console window. But I want to run in a "batch" mode where the app is
> > launched without a window. In this mode I still get all Console.WriteLine
> > and Console.Error.WriteLine output properly redirected, but lose all
> > output
> > from the unmanaged DLLs.
> >
> > Is there anything I can do to get output from an unmanaged, PInvoke'd DLL
> > to
> > get redirected properly?
> >
> > Thanks!
> > -- Tom
> >
>
>
>
.



Relevant Pages

  • Re: working set and console applications
    ... I created a windows application and then I created a child console process ... that I started from the parent process using CreateProcess. ... I minimize the child console window it also causes the working set of the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Console applications window size
    ... AllocConsole() or AttachConsole. ... You already have a console, ... SMALL_RECT srWindowRect; // hold the new window size ... >exe from a cmd prompt, the same cmd prompt gets bigger properly. ...
    (microsoft.public.vc.language)
  • Re: How to minimize command mode window in console program?
    ... to set some property to minimize the console window. ...     ByVal hWnd As IntPtr, ...     End Sub ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Prevent Domain Users From Browsing Around in Active Directory?
    ... View, Customize, uncheck everything except the top one that says Console ... But they will have the rt-click feature. ... Rt-click on that OU, new window from here. ...
    (microsoft.public.windows.server.active_directory)
  • Re: vb6 run from and output to command window
    ... VB doesn't really create true console applications (because the linker ... allocate the console window, and read/write from/to it. ... Private Declare Function AllocConsole Lib "kernel32" As Long ... Dim lResult As Long ...
    (microsoft.public.vb.general.discussion)

Loading