重定向控制台输出以查找命令失败的迹象

时间:2011-05-27 18:06:15

标签: vb.net visual-studio-2010

我正在列表中的所有计算机上运行命令。我试图找回每个计算机上显示PASS或FAIL的文本文件。我正在使用下面的StreamWriter和函数进程。该进程正确运行,并且对数据文件和错误日志都具有权限。然而,错误日志总是说PASS表示一切。

我无法在控制台窗口中看到任何内容。我如何知道如何设置if consoleOutput =“????”到?

       Using swrr As New StreamWriter(ErrorLog, True)
        For Each strUserName As String In strLines

            Dim ConsoleOutput As String = GetCMDOutput(strUserName, saveFileDialog3.FileName & ".txt", exeSearch)
            Console.ReadLine()

            If ConsoleOutput = "blahblah" Then swrr.WriteLine("FAIL") Else swrr.WriteLine("PASS")
        Next

    End Using




Function GetCMDOutput(ByVal strUsername As String, ByVal strFileName As String, ByVal strExeSearch As String) As String
    Dim Arg1 As String = strUsername
    Dim Arg2 As String = strFileName
    Dim Final As String = String.Format("/c pushd\\{0}\C$ && whoami.exe >> {1}", Arg1, Arg2)

    Dim CMD As New Process

    CMD.StartInfo.FileName = "cmd.exe"
    CMD.StartInfo.Arguments = Final
    CMD.StartInfo.UseShellExecute = False
    CMD.StartInfo.RedirectStandardOutput = True
    CMD.StartInfo.RedirectStandardInput = True
    CMD.StartInfo.CreateNoWindow = True
    CMD.Start()

    Dim retval As String = CMD.StandardOutput.ReadToEnd
    CMD.WaitForExit()
    Return retval

End Function

1 个答案:

答案 0 :(得分:1)

观看此视频,了解如何在visual studio中进行调试:

http://www.youtube.com/watch?v=4uyDBM-qTkk