Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Go Back  Xtreme Visual Basic Talk > > > Capturing Console - VB 2008 Express Edition


Reply
 
Thread Tools Display Modes
  #1  
Old 08-20-2009, 11:08 AM
msturgeo msturgeo is offline
Newcomer
 
Join Date: Aug 2009
Location: US
Posts: 2
Default Capturing Console - VB 2008 Express Edition


Hi All,

Before I begin - this is my first post and I am glad to have found your forums. Thank you in advance.

After searching the forums - I found Squirms posting here:
Console Capture

Since it was in the Legacy VB forums I do not think it applies to the VB 2008 Xpress edition that I am working with but I might be wrong. I am a hobbyist here and do not have any professional training. However I am good with tinkering and have had some success in building small VB applications.

I do not think what I am asking is hard to do for someone with more experience. I am hopeful that after spending countless hours on the web, via google, and making little progress - someone here will just help open this door for me.

My application is simple. It is a console app - no buttons or GUI. I want a person to run it so it returns some basic configuration about their computer. I have managed to complete a working application that will gather information using the following code. Here is my question:

How can I get the TEXTWRITERTRACELISTENER to write the output to myFile when I call SYSTEM.DIAGNOSTICS.PROCESS.START ("IPCONFIG", "/ALL")

Here is the code:

Code:
Imports System.IO
Imports System.Diagnostics.Process
Imports System.ComponentModel


Module Module1


#Const TRACE = True

    Public Class ConsoleTraceSample

        ' Define a simple method to write details about the current executing 
        ' environment to the trace listener collection.


        Public Shared Sub WriteEnvironmentInfoToTrace()

            Dim myFile As Stream = File.Create("C:\NewTestFile.txt")
            Dim myTextListener As New TextWriterTraceListener(myFile)
            Trace.Listeners.Add(myTextListener)


            Dim methodName As String = "WriteEnvironmentInfoToTrace"


            Trace.Indent()
            Trace.WriteLine(DateTime.Now.ToString() & " - Start of " & methodName)
            Trace.Indent()

            ' Write details on the executing environment to the trace output.
            Trace.WriteLine("Operating system: " & _
                System.Environment.OSVersion.ToString())
            Trace.WriteLine("Computer name: " & System.Environment.MachineName)
            Trace.WriteLine("User name: " & System.Environment.UserName)
            Trace.WriteLine("CLR version: " & System.Environment.Version.ToString)
            Trace.WriteLine("Command line: " & System.Environment.CommandLine)
            Trace.WriteLine("User Domain name: " & System.Environment.UserDomainName)
            Trace.WriteLine("System Directory: " & System.Environment.SystemDirectory)

            'Here is where I would like to call the IPCONFIG but output only gets written
            'in myFile the same as the line - I do not get the console output. Please help?
            Trace.WriteLine(System.Diagnostics.Process.Start("ipconfig", "/all"))

            'End Help Request - Thanks! 

            ' Enumerate the trace listener collection and 
            ' display details about each configured trace listener.
            Trace.WriteLine("Number of configured trace listeners = " & _
                Trace.Listeners.Count.ToString())

            Dim tl As TraceListener
            For Each tl In Trace.Listeners
                Trace.WriteLine("Trace listener name = " & tl.Name)
                Trace.WriteLine("               type = " & tl.GetType().ToString())
            Next tl

            Trace.Unindent()
            Trace.WriteLine(DateTime.Now.ToString() & " - End of " & methodName)
            Trace.Unindent()


        End Sub

        ' Define the main entry point of this class.
        ' The main method adds a console trace listener to the collection
        ' of configured trace listeners, then writes details on the current
        ' executing environment.
        Public Shared Sub Main(ByVal CmdArgs() As String)
            MsgBox("TEST")
            ' Write a trace message to all configured trace listeners.
            Trace.WriteLine(DateTime.Now.ToString() & " - Start of Main")

            ' Define a trace listener to direct trace output from this method
            ' to the console.
            Dim consoleTracer As ConsoleTraceListener

            ' Check the command line arguments to determine which
            ' console stream should be used for trace output.
            If (CmdArgs.Length > 0) AndAlso _
               (CmdArgs(0).ToLower.Equals("/stderr")) Then
                ' Initialize the console trace listener to write
                ' trace output to the standard error stream.
                consoleTracer = New ConsoleTraceListener(True)
            Else
                ' Initialize the console trace listener to write
                ' trace output to the standard output stream.
                consoleTracer = New ConsoleTraceListener
            End If
            ' Set the name of the trace listener, which helps identify this 
            ' particular instance within the trace listener collection.
            consoleTracer.Name = "mainConsoleTracer"

            ' Write the initial trace message to the console trace listener.
            consoleTracer.WriteLine(DateTime.Now.ToString() & " [" & _
                 consoleTracer.Name & "] - Starting output to trace listener.")

            ' Add the new console trace listener to 
            ' the collection of trace listeners.
            Trace.Listeners.Add(consoleTracer)

            ' Call a local method, which writes information about the current 
            ' execution environment to the configured trace listeners.
            WriteEnvironmentInfoToTrace()

            ' Write the final trace message to the console trace listener.
            consoleTracer.WriteLine(DateTime.Now.ToString() & " [" & _
                consoleTracer.Name & "] - Ending output to trace listener.")

            ' Flush any pending trace messages, remove the 
            ' console trace listener from the collection,
            ' and close the console trace listener.

            Trace.Flush()
            Trace.Listeners.Remove(consoleTracer)
            consoleTracer.Close()

            ' Write a final trace message to all trace listeners.
            Trace.WriteLine(DateTime.Now.ToString() + " - End of Main")

            ' Close all other configured trace listeners.
            Trace.Close()

            End Sub
    End Class
End Module
Reply With Quote
  #2  
Old 08-24-2009, 12:02 PM
msturgeo msturgeo is offline
Newcomer
 
Join Date: Aug 2009
Location: US
Posts: 2
Smile I have solved my own problem

Hi,

The solution was really to create a new streamwriter and create a batch file, and then run it, then later append the trace listener output to the file created by the standard ">" pipe output of ipconfig.exe using the DOS command.

Here is an example of the new code for reference. I hope it helps someone else out.

Code:
Public Shared Sub WriteEnvironmentInfoToTrace()

            MSGBOX("PROGRAM STARTING")
            'Start a StreamWriter
		Dim oWrite As System.IO.StreamWriter
            
		'Create a Batch File
		oWrite = IO.File.CreateText("c:\Config.bat")


        
            'Fill the Batch file with a command - Run the Bat'
            oWrite.WriteLine("c:\windows\system32\ipconfig.exe /all > c:\Iplog.txt ")
            oWrite.Flush()
            oWrite.Close()
            System.Threading.Thread.Sleep(1000)
            Start("c:\config.bat")
            System.Threading.Thread.Sleep(1000)

		
            'End Batch File Create

            'Append Output of New Tracelistener to the Same File as created by the Batch file
		Dim myFile As String = ("C:\Iplog.txt")
            Dim myTextListener As New TextWriterTraceListener(myFile)
            Trace.Listeners.Add(myTextListener)


            Dim methodName As String = "WriteEnvironmentInfoToTrace"


            Trace.Indent()
            Trace.WriteLine(" ") 'add a space
            Trace.WriteLine(DateTime.Now.ToString() & " - Start of " & methodName)
            Trace.Indent()
            ' Write details on the executing environment to the trace output.
            Trace.WriteLine("Operating system: " & _
                System.Environment.OSVersion.ToString())
            Trace.WriteLine("Computer name: " & System.Environment.MachineName)
            Trace.WriteLine("User name: " & System.Environment.UserName)
            Trace.WriteLine("CLR version: " & System.Environment.Version.ToString)
            Trace.WriteLine("Command line: " & System.Environment.CommandLine)
            Trace.WriteLine("User Domain name: " & System.Environment.UserDomainName)
            Trace.WriteLine("System Directory: " & System.Environment.SystemDirectory)


            ' Enumerate the trace listener collection and 
            ' display details about each configured trace listener.
            Trace.WriteLine("Number of configured trace listeners = " & _
                Trace.Listeners.Count.ToString())

            Dim tl As TraceListener
            For Each tl In Trace.Listeners
                Trace.WriteLine("Trace listener name = " & tl.Name)
                Trace.WriteLine("               type = " & tl.GetType().ToString())
            Next tl

            Trace.Unindent()
            Trace.WriteLine(DateTime.Now.ToString() & " - End of " & methodName)
            Trace.Unindent()


        End Sub

        ' Define the main entry point of this class.
        ' The main method adds a console trace listener to the collection
        ' of configured trace listeners, then writes details on the current
        ' executing environment.
        Public Shared Sub Main(ByVal CmdArgs() As String)
            
            ' Write a trace message to all configured trace listeners.
            Trace.WriteLine(DateTime.Now.ToString() & " - Start of Main")

            ' Define a trace listener to direct trace output from this method
            ' to the console.
            Dim consoleTracer As ConsoleTraceListener

            ' Check the command line arguments to determine which
            ' console stream should be used for trace output.
            If (CmdArgs.Length > 0) AndAlso _
               (CmdArgs(0).ToLower.Equals("/stderr")) Then
                ' Initialize the console trace listener to write
                ' trace output to the standard error stream.
                consoleTracer = New ConsoleTraceListener(True)
            Else
                ' Initialize the console trace listener to write
                ' trace output to the standard output stream.
                consoleTracer = New ConsoleTraceListener
            End If
            ' Set the name of the trace listener, which helps identify this 
            ' particular instance within the trace listener collection.
            consoleTracer.Name = "mainConsoleTracer"

            ' Write the initial trace message to the console trace listener.
            consoleTracer.WriteLine(DateTime.Now.ToString() & " [" & _
                 consoleTracer.Name & "] - Starting output to trace listener.")

            ' Add the new console trace listener to 
            ' the collection of trace listeners.
            Trace.Listeners.Add(consoleTracer)

            ' Call a local method, which writes information about the current 
            ' execution environment to the configured trace listeners.
            WriteEnvironmentInfoToTrace()

            ' Write the final trace message to the console trace listener.
            consoleTracer.WriteLine(DateTime.Now.ToString() & " [" & _
                consoleTracer.Name & "] - Ending output to trace listener.")

            ' Flush any pending trace messages, remove the 
            ' console trace listener from the collection,
            ' and close the console trace listener.

            Trace.Flush()
            Trace.Listeners.Remove(consoleTracer)
            consoleTracer.Close()

            ' Write a final trace message to all trace listeners.
            Trace.WriteLine(DateTime.Now.ToString() + " - End of Main")

            ' Close all other configured trace listeners.
            Trace.Close()
		MSGBOX("PROGRAM FINISHED")
Reply With Quote
Reply


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
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
 
Capturing Console - VB 2008 Express Edition
Capturing Console - VB 2008 Express Edition
 
-->