我有一个VB.net程序,我在其中调用Shell函数。我想在文件中获取从此代码生成的文本输出。但是,这不是执行代码的返回值,所以我真的不知道该怎么做。在VB.net中获取shell命令的输出
这个程序是一个服务,但可以访问磁盘没有问题,因为我已经记录其他信息。整个服务有多个线程,所以我还必须确保在写入文件时它还没有被访问。
我有一个VB.net程序,我在其中调用Shell函数。我想在文件中获取从此代码生成的文本输出。但是,这不是执行代码的返回值,所以我真的不知道该怎么做。在VB.net中获取shell命令的输出
这个程序是一个服务,但可以访问磁盘没有问题,因为我已经记录其他信息。整个服务有多个线程,所以我还必须确保在写入文件时它还没有被访问。
您将无法捕获Shell的输出。
您需要将这个改变的过程,你会需要捕获的Standard Output(也可能是错误)从工艺流。
下面是一个例子:
Dim oProcess As New Process()
Dim oStartInfo As New ProcessStartInfo("ApplicationName.exe", "arguments")
oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oProcess.StartInfo = oStartInfo
oProcess.Start()
Dim sOutput As String
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
sOutput = oStreamReader.ReadToEnd()
End Using
Console.WriteLine(sOutput)
Dim proc As New Process
proc.StartInfo.FileName = "C:\ipconfig.bat"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
proc.WaitForExit()
Dim output() As String = proc.StandardOutput.ReadToEnd.Split(CChar
(vbLf)) 对于每个LN作为字符串在输出 RichTextBox1.AppendText(LN & vbNewLine) lstScan.Items.Add(LN & vbNewLine ) 接着
=========================================== ============================ 创建一个如下图所示在两行批处理文件:
呼应关闭
IPCONFIG
“确保你这个批处理文件保存为ipconfig.bat或任何名u决定选择,但要确保ü把点蝙蝠在它的结尾。
哇,对于这样一个小小的壮举来说这很复杂...... – 2012-01-11 13:25:02