如何解决重定向控制台输出以查找命令失败的迹象
| 我正在列表中的所有计算机上运行命令。我正在尝试找回每台计算机上通过或失败的文本文件。我正在使用下面的StreamWriter和函数过程。该过程正确运行,并且对数据文件和错误日志均具有权限。但是,错误日志始终对所有内容显示“通过”。 我无法在控制台窗口中看到任何内容。我如何知道如果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
解决方法
观看此视频,了解如何在Visual Studio中进行调试:
http://www.youtube.com/watch?v=4uyDBM-qTkk
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。