acquiring standard out, standard error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have managed to acquire the standard out & error streams of an app by
starting it with System.Diagnostics.Process. Works great.

How do I acquire the standard output & error & in streams of an already
running application, for instance, a service. Basically I need to monitor the
standard out & error streams of a running app from another app.

Thanks
Paul
 
Hi Paul,

Can you be specific what output generated by the service application you
want to monitor? Based on my knowledge, Windows Service applications do not
generate any UI with the users, so normally service application does not
generate any UI output with standard console APIs.

Normally, service application serves in the background without UI and sends
any output through interprocess communication technologies to another GUI
application. For example, SQL Server service runs in the background without
any visibility, it will communicate with "Enterprise Manager" application
to administrator its content and operations. As you can see, there is no
"Standard Output" concept for SQL Server service.

I will wait for your further confirmation. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Jeffrey,

Thanks for your reply.

1. Thanks, I understand your point about services not generating UI content.
What would be the recommended way in .Net to communicate between a service
and a service manager (like SQL and Enterprise manager)?

2. If I want to tap in to the standard out & error of an app that is already
running, how would I do that? Is it possible?

Regards
Paul
 
Hi Paul,

Thanks for your feedback.

Service is a normal process, its only difference between other processes
are the window station(logon session) boundary. GUI messages/hooks can not
be used across window station boundary. So the communication between
service process and the SCP(Service Control Program) process can be any IPC
technologies except "Windows Message".

In Win32 world, I normally use named pipe for the IPC channel. However,
since named pipe is not encapsulated in .Net, the 2 recommended ways for
IPC in .Net are .Net remoting and socket. The 2 articles demonstrate these
2 technologies using in Windows Service:
"A TCP/IP Server written in C#"
http://www.codeproject.com/cs/internet/tcpserverall.asp
"How To Host .NET Remoting Objects In Windows Service Application"
http://www.codeproject.com/Purgatory/winservicehost.asp

Windows provided limited set of functions for cross-processes accessing,
they are WriteProcessMemory, CreateRemoteThread, VirtualAllocEx, etc...
Other Win32 API functions will only function in current process. More
specificly, Windows console APIs GetStdHandle, CreateFile,
CreateConsoleScreenBuffer and SetStdHandle to manipulate the console
standard output/input. However, all these APIs will take effect in a single
process and can not be used for another process, below article provided
more information regarding console handles:
"Console Handles"
http://windowssdk.msdn.microsoft.com/en-us/library/ms682075(VS.80).aspx

The reason that child process can be redirected standard output/input is
that the parent process passed the redirected pipe handles in CreateProcess
API's STARTUPINFO structure. CreateProcess API internally will help to
redirect the child process's standard output/input. Without child/parent
processes relation, we can not get the help of CreateProcess, and Windows
did not provide other documented way to redirect another process's standard
output/input.

If you really wanted to get this task done, my thought is injecting another
dll into the remote process. In the DllMain of this dll, your code is
executing in that process space now, you can call SetStdHandle API to
redirect the remote process's standard output/input. This is a pure Win32
cross process hijacking technology which can not be done in .Net. I mean,
the injected dll must be written with unmanaged C/C++ code, can not be the
..Net assembly.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top