在列表框中显示命令提示符中显示的消息
实际上,我想显示 cmd 提示符中显示的消息,例如:
Ping google.com -t
以下消息将显示在 cmd 提示符中:
Reply from 74.125.235.17: bytes=32 time=133ms TTL=51
Reply from 74.125.235.17: bytes=32 time=130ms TTL=51
Reply from 74.125.235.17: bytes=32 time=130ms TTL=51
Reply from 74.125.235.17: bytes=32 time=130ms TTL=51
Ping statistics for 74.125.235.17:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 130ms, Maximum = 133ms, Average = 130ms
我想将确切的信息显示到我的程序的列表框在命令提示符中显示时立即显示,而不是在整个过程完成后。我怎样才能这样做?有什么帮助吗?我正在使用 C#/vb.net 。
就像在 ping google.com -t 中一样,我想在列表框中立即显示每条回复消息。
Actually I want to display the messages shown in cmd prompt like, if i do:
Ping google.com -t
The following message will be displayed in the cmd prompt:
Reply from 74.125.235.17: bytes=32 time=133ms TTL=51
Reply from 74.125.235.17: bytes=32 time=130ms TTL=51
Reply from 74.125.235.17: bytes=32 time=130ms TTL=51
Reply from 74.125.235.17: bytes=32 time=130ms TTL=51
Ping statistics for 74.125.235.17:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 130ms, Maximum = 133ms, Average = 130ms
I want to display the exact information into the list box of my program instantly when it is displayed in the command prompt not after whole process is completed. How can i do so? Any help? I am using C#/vb.net .
As in the ping google.com -t, I want to display the each reply message instantly in the list box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为此,您需要利用标准输出上的异步读取...另请参阅此...
在这里您可以找到所描述问题的解决方案以及完整的源代码。 ..它甚至考虑了 stderr...
其他有趣的资源:
For this you need to utilize async read on standardoutput... see also this...
Here you can find a solution for the described problem complete with source code... it even takes stderr into account...
Other interesting resources:
试试这个:
Try this:
为您快速解决。
将输出重定向到 C:\ping.txt
“Ping google.com -t > C:\ping.txt”
每 x 秒读取 ping.txt
File.ReadAllText("C:\ping.txt")
更新列表框UI安全线程参考
如何从 C# 中的另一个线程更新 GUI?
Quick solution for you.
Redirect output to C:\ping.txt
"Ping google.com -t > C:\ping.txt"
Read ping.txt every x second(s)
File.ReadAllText("C:\ping.txt")
Update ListBox in an UI safe thread refer to
How to update the GUI from another thread in C#?