控制台输出到字符串

问题描述:

我正在处理一个小应用程序,它需要将dsquery和dsget的结果设置为字符串进行清理(替换空格和其他不需要的字符)。我可以使用ReadToEnd显示流的结果 - 但似乎无法找到任何有关将其转换为字符串的内容。控制台输出到字符串

VB.net - 的Visual Basic 2010

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim p As New Process 
    p.StartInfo.UseShellExecute = False 
    p.StartInfo.CreateNoWindow = True 
    p.StartInfo.FileName = "program" 
    p.StartInfo.Arguments = "lots here" 
    p.StartInfo.RedirectStandardOutput = True 
    p.Start() 
    Dim reader As StreamReader = p.StandardOutput 
    p.WaitForExit() 
    MsgBox(reader.ReadToEnd) 
End Sub 
+0

只是在reader.ReadToEnd`的`末尾添加括号。 – 2014-04-24 03:08:13

只写

dim ProcOutput as string 
ProcOutput = reader.ReadToEnd() 

,而不是最后一行。

如果这样做没有帮助,那么我建议你看看这篇文章:

http://www.codeproject.com/KB/threads/launchprocess.aspx