473,426 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

How to get stdout/stderr from unmanaged DLL?

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

Nov 17 '05 #1
2 5885
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" <th************@countrywide.NOSPAM.com> wrote in message
news:00**********************************@microsof t.com...
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

Nov 17 '05 #2
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" <th************@countrywide.NOSPAM.com> wrote in message
news:00**********************************@microsof t.com...
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


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
3
by: Laszlo Zsolt Nagy | last post by:
Hello, I have this code: s = smtplib.SMTP() s.set_debuglevel(1) s.connect(host=smtp_host) s.set_debuglevel(0) log("Connected, sending e-mail") sys.stdout.flush()
7
by: Andre | last post by:
Hi, I have a program that sends some output to stdout and some to stderr. I need to separate the two using the command-line so that I direct stderr output to a file, say fileA.txt, and stdout...
0
by: Christoph Haas | last post by:
Evening, I'm having trouble with running a process through Python 2.4's subprocess module. Example code: ======================================================== def run(command): run =...
2
by: Massi | last post by:
Hi everyone! I'm writing a python script which uses a C-written dll. I call the functions in the dll using ctypes, but I don't know how to catch the output of the "printf" which the C functions...
10
by: SamG | last post by:
How could i make, from inside the program, to have the stdout and stderr to be printed both to a file as well the terminal(as usual).
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to...
2
by: Guillaume Dargaud | last post by:
Hello all, a while ago I was pointed towards freopen as a way to redirect stderr to a log file. It works great, but apparently the app also writes a few lines to stdout. Now I could redirect to 2...
4
by: lovecreatesbea... | last post by:
For example, in Bourne Shell both stdout and stderr can be re-directed to /dev/null, $ ./a.out 2>&1 /dev/null then is there any difference still?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.