如何开始一个可见的过程

时间:2014-12-09 11:29:28

标签: vb.net process

我有以下代码来启动程序R(尽管我认为该程序与此处的问题无关)并运行脚本:

Public Shared Sub RunRScript(rCodeFilePath As String, rScriptExecutablePath As String, args As String)

    Dim file As String = rCodeFilePath
    Dim result As String = String.Empty

    Try
        Dim info = New ProcessStartInfo()
        info.FileName = rScriptExecutablePath
        info.WorkingDirectory = Path.GetDirectoryName(rScriptExecutablePath)
        info.Arguments = rCodeFilePath & " " & args

        info.RedirectStandardInput = False
        info.RedirectStandardOutput = True
        info.UseShellExecute = False
        info.CreateNoWindow = True

        Using proc = New Process()
            proc.StartInfo = info
            proc.Start()
            result = proc.StandardOutput.ReadToEnd()
            proc.Close()
        End Using
    Catch ex As Exception
        Throw New Exception("R Script failed: " & result, ex)
    End Try
End Sub

问题是,如果我在R中运行的脚本中出现错误,则不会收到错误消息,因为该实例是不可见的。我尝试用

显示它
.WindowStyle = ProcessWindowStyle.Normal
<。>在.UseShellExcecute和.CreateNoWindow的所有组合中,但这不起作用。任何人都可以帮助我使我的过程可见吗?

1 个答案:

答案 0 :(得分:3)

由于您要重定向StandardInput和StandardOutput,现在应该重定向StandardError以捕获错误。 有关详情,请访问MSDN