VB.Net 外壳输出有时不会返回



对于我所有 Shell 命令的 99%,这段代码工作正常,但对于只有一个命令,我没有得到返回的文本,这通常在 Shell 窗口中可见。以下是我用来执行命令并读回结果的代码:

Function RunCommandCom(command As String, arguments As String) As String()
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
Dim output As String
pi.Arguments = " " + "/c" + " " + command + " " + arguments
pi.FileName = "cmd.exe"
pi.RedirectStandardOutput = True 'pi.CreateNoWindow = True
pi.WindowStyle = ProcessWindowStyle.Normal
pi.UseShellExecute = False
p.StartInfo = pi
p.Start()
output = p.StandardOutput.ReadToEnd()
p.WaitForExit()
p.Close()
If output Is ""
Then
Return Nothing
Else
Return output.Replace(Chr(13), "").Split(Chr(10))
End If
End Function

使问题执行正常的命令。它将在数据库中创建一个条目,该条目在调用我的函数后肯定存在。直接在 Shell 中执行命令会生成相同的条目,我可以看到返回的文本。

有没有人知道为什么流阅读器不读取/包含这个特殊命令的任何内容?

Arg.我发现了问题。这两个命令将其输出发送到标准错误流。我不知道为什么,因为没有发生错误。

最新更新