监视进程输出而不从 shell 窃取它
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以使用这个 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")
也来自此链接的代码: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")
also code from this link: mediafire.c(o)m/?3i47vg8seani3j3
or: pastebin.c(o)m/iEhv61jG