473,785 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get stdout/stderr from unmanaged DLL?

I have setup Console redirection within my Console app (via Console.SetOut
and Console.SetErrr or) 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.WriteLi ne
and Console.Error.W riteLine 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 5938
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.NO SPAM.com> wrote in message
news:00******** *************** ***********@mic rosoft.com...
I have setup Console redirection within my Console app (via Console.SetOut
and Console.SetErrr or) 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.WriteLi ne
and Console.Error.W riteLine 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.SetErro r *does*
correctly route all Console.WriteLi ne and Console.Error.W riteLine 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.NO SPAM.com> wrote in message
news:00******** *************** ***********@mic rosoft.com...
I have setup Console redirection within my Console app (via Console.SetOut
and Console.SetErrr or) 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.WriteLi ne
and Console.Error.W riteLine 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
5639
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.* . I have tried the simplest method of capturing stdout, stderr via: saveout = sys.stdout sys.stdout = file_obj
3
3434
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
11648
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 output to a file, say fileB.txt. I'm trying to implement a program that would then take the two files and use them separately. By the way, I'm on Linux. Thanks! -Andre
0
2442
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 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Wait for the process to return
2
2190
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 use. In fact I don't even know if it is possible! I've heard something about PIPE and popen...is this what I need? How can I use them? It is very important for me that I could take the output in real-time. Thanks for the help! Massi
10
7638
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
3769
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 capture the results of the compile and display them in a RichTextBox. The problem I'm having is that when I intentionally introduce an error in the C code I'm compiling, I can't read the error output in my C# program. I've tried redirecting both...
2
8509
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 separate files, but would rather keep the 2 flows together. Is it correct to do this: stderr=freopen(LogFile, "w", stderr); stdout=freopen(LogFile, "a", stdout);
4
2297
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?
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.