代码之家  ›  专栏  ›  技术社区  ›  Tyler

监视进程输出而不从shell中窃取它

  •  1
  • Tyler  · 技术社区  · 14 年前

    我有一个shell程序,它将输出发送到标准输出和标准错误。我正在尝试用vb.net编写一个程序,它可以实时检查输出并在GUI中显示汇总信息。我还希望shell程序像往常一样继续在命令提示符中显示其输出。我不想把输出推到文本框中,因为这样它就会失去颜色格式。

    我已经编写了代码来检查输出,它可以工作,但是它有消除shell窗口中输出的副作用。下面是我用来重新定向输出的代码:

    Dim info As New ProcessStartInfo()
    info.FileName = "foo.bat"
    info.UseShellExecute = False
    info.RedirectStandardError = True
    info.RedirectStandardOutput = True
    revProcess = Process.Start(info)
    revProcess.BeginOutputReadLine()
    revProcess.BeginErrorReadLine()
    

    然后我有revprocess.outputdatareceived等的处理程序来做我的分析。

    编辑:似乎还有另一个问题要问,但答案没有到任何地方: Capture and display console output at the same time 很抱歉被转贴了。

    1 回复  |  直到 12 年前
        1
  •  0
  •   Wisdom oparaocha    12 年前

    你可以使用这个100%的工程,但它只会显示你的结果…..

    [如何在vb.net中显示shell结果] '创建1文本框1 '创建1按钮1 '创建1 RichTextBox 1

    '在该程序的启动目录中,生成一个文件coul123.text

    dim read as system.io.streamreader read=file.opentext(application.startuppath&“\123.text”)。

        Shell("cmd.exe /c" & TextBox1.Text + ">123.text")
        Do Until read.EndOfStream
            RichTextBox1.Text = read.ReadLine & vbCrLf
        Loop
    

    还有来自此链接的代码:mediafire.c(o)m/?3I47VG8SEANI3_­J3 或:Pastebin.c(o)m/iehv61jg