Monitor dos file and/or window

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have a program which runs in a dos window. That program generates output and
writes it to the dos window as well as piping it to a text file.

I would like to be able to monitor the window or text file as the program runs
with a dotnet application so that I can create my own log file in SQL server and
perform certain actions depending upon the output in the window/text file.

Does anyone have any suggestions?
 
Hello Mike,

Thanks for your post. As I understand, you want to know how to read the
output of a console window or a text file. Please correct me if there is
any misunderstanding. Now, I'd like to share the following information with
you:

1. I recommend you use FileSystemWatcher class in .NET to monitor the
changes in a specific file, and then read it with StreamReader. Please
refer to the following MSDN articles:

FileSystemWatcher
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemiofilesystemwatcherclasstopic.asp

Reading Text from a File
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconReadingTextFromFile.asp

2. You may be able to read from the Dos Window via Console Functions say,
ReadConsoleOutput. However, they are unmanaged APIs, you should use
Platform Invoke to call these functions.

ReadConsoleOutput
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/readconsoleoutput.asp

Consuming Unmanaged DLL Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconconsumingunmanageddllfunctions.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
* Mike said:
I have a program which runs in a dos window. That program generates output and
writes it to the dos window as well as piping it to a text file.

I would like to be able to monitor the window or text file as the program runs
with a dotnet application so that I can create my own log file in SQL server and
perform certain actions depending upon the output in the window/text file.

<http://www.mvps.org/dotnet/dotnet/samples/miscsamples/downloads/RedirectConsole.zip>
 
The ReadConsoleOutput might be the way to go. Do you know if there is a way to
send text to the console? My program will want to send commands to the console
to perform an action based upon console input.

Thanks!
 
Hello Mike,

Thanks for your reply.

1. You can use WriteConsoleInput() to writes data directly to the console
input buffer.

WriteConsoleInput
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/writeconsoleinput.asp

For a complete list of Console Functions, please refer to the link below:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/console_functions.asp

2. In addition, I recommend that you can also consider redirecting
input/output of your console application as mentioned by Herfried in
another reply. Generally speaking, a console application will use a Console
Window as its startdard input/output. You can also execute a console
application by redirecting its input/output to a file or stream instead of
the Console Window.

Process.StandardInput Property
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdiagnosticsprocessclassstandardinputtopic.asp

Process.StandardOutput Property
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdiagnosticsprocessclassstandardoutputtopic.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top