How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application?
How do I get the text of a Windows console application? How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
Go Back  Xtreme Visual Basic Talk > > > How do I get the text of a Windows console application?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2016, 06:09 AM
jvgdmac jvgdmac is offline
Newcomer
 
Join Date: Aug 2016
Posts: 1
Default How do I get the text of a Windows console application?


I'm using VB 2010 to automate an application running on an external Windows console (cmd.exe). Note that I want to continue using the external console normally but, from time to time, I want to capture the console text from the VB application. I have no problem to send text commands to the console from buttons on my VB application using, for example:

Code:
...
Dim As IntPtr = FindWindow destination ("ConsoleWindowClass", "consoleapp")
SendMessage (destination, WM_CHAR, VK_RETURN, "")
...
However, it seems impossible to get the text that appears in the console window. I tried using standard output redirection:

Code:
...
oStartInfo = New ProcessStartInfo ("consoleapp.exe")
oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oProcess.StartInfo = oStartInfo
oProcess.Start ()
...
And then I read the output stream using:

Code:
...
Dim oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
sOutput = oStreamReader.ReadLine ()
...
This way I can read the standard output from my VB application, but I can not use the console because the console does not show any text (since it has been redirected!). On the other hand, you can not change the standard output redirection once the console process is started.

I have also tried to use 'GetWindowText', but does not work with windows belonging to other applications.

Now I am using 'SendMessage' and 'WM_GETTEXT' as follows:

Code:
...
Dim windowhandle As IntPtr = FindWindow ("ConsoleWindowClass", "consoleapp")
Dim ChildHandle As IntPtr = FindWindowEx (windowhandle, IntPtr.Zero, Nothing, Nothing)
Dim RcvText As String

'Alloc memory for the buffer That recieves the text
Dim mybuffer As IntPtr = Marshal.AllocHGlobal (200)

'The WM_GETTEXT Send Message
SendMessage (ChildHandle, WM_GETTEXT, 200, mybuffer)

'Copy the characters from the unmanaged memory to a managed string
RcvText = Marshal.PtrToStringUni(mybuffer)

'Display the string
Debug.Print (RcvText)
...
But all I get are strange text strings, but nothing of the text content of the console.

Since the console window has no child windows, I tried to use SendMessage (Windowhandle...) instead of SendMessage (ChildHandle...), but the result is also weird strings ...

Is there a way to read the text of a Windows console using VB?

Thank you very much for your help.
Reply With Quote
Reply

Tags
console, text, dim, windows, sendmessage, application, intptr, output, standard, wm_gettext, childhandle, string, windowhandle, rcvtext, read, external, ostartinfo, redirection, mybuffer, strings, memory, window, findwindow, destination, consoleapp


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application? How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application? How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
 
How do I get the text of a Windows console application?
How do I get the text of a Windows console application?
 
-->