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

发布于 2024-09-25 21:01:08 字数 723 浏览 8 评论 0原文

我有一个 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 等的处理程序来进行分析。

编辑:看起来还有另一个问题,但答案没有去任何地方: 同时捕获并显示控制台输出 抱歉重新发布。

I have a shell program that sends output to standard out and standard error. I am trying to write a program in VB.net which inspects the output in real time and presents summarized information in a GUI. I also want the shell program to continue to display its output in a command prompt as usual. I don't want to just shove the output in a text box because then it seems to lose its color formatting.

I have written code to inspect the output, and it works, but it has the side effect of eliminating the output in the shell window. Here is the code I use to begin redirecting output:

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()

And then I have handlers for revProcess.OutputDataReceived, etc. to do my analysis.

Edit: Looks like there was another question for this, but the answers didn't go anywhere: Capture and display console output at the same time sorry for the repost.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴随着你 2024-10-02 21:01:08

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

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

' 在该程序的启动目录中创建一个文件,可以将 123.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/?3i47vg8seani3j3
或:pastebin.c(o)m/iEhv61jG

you can use this 100% works but it will only show you the results.....

[how to show shell results in vb.net]
'create 1 textbox1
'create 1 button1
'create 1 richtextbox1

'in the start up directory of this program make a file could 123.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

also code from this link: mediafire.c(o)m/?3i47vg8seani3­j3
or: pastebin.c(o)m/iEhv61jG

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文