VB.NET - Working with Console Applications



Capture Output from a Console Application

'Assembly: System.dll
'Namespace: System
'Namespace: System.Diagnostics
'Namespace: Microsoft.VisualBasic

'Console Application: "cmd.exe"

Dim consoleApp As New Process
With consoleApp
    .StartInfo.UseShellExecute = False
    .StartInfo.RedirectStandardOutput = True
    .StartInfo.FileName = "cmd.exe"
    .Start()
    .WaitForExit()
End With

Dim output As String = consoleApp.StandardOutput.ReadToEnd()

Change the Foreground and Background Colors in a Console Window

'Namespace: Microsoft.VisualBasic

Console.BackgroundColor = ConsoleColor.DarkRed
Console.ForegroundColor = ConsoleColor.Gray
Console.Clear()

Send Keystrokes to an Application

'Assembly: System.Windows.Forms.dll
'Namespace: Microsoft.VisualBasic
'Namespace: System.Windows.Forms

'Keystroke: ENTER KEY

SendKeys.SendWait("{ENTER}")

Read and Write from the Console Window

'Namespace: Microsoft.VisualBasic

Console.WriteLine("Enter your name:")
txtName = Console.ReadLine()
Console.WriteLine(txtName)

Clear the Console Window

'Namespace: Microsoft.VisualBasic

Console.Clear()

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.