【发布时间】:2014-03-25 04:51:17
【问题描述】:
我正在通过 VB.net 开发一个项目,我正在使用 CMD 执行我想知道如何将 CMD 的结果复制到我的主窗体上的文本框中的命令
【问题讨论】:
我正在通过 VB.net 开发一个项目,我正在使用 CMD 执行我想知道如何将 CMD 的结果复制到我的主窗体上的文本框中的命令
【问题讨论】:
在此处查看接受的答案:Get the output of a shell Command in VB.net。这可能就是您所需要的。
另外,这里是将结果放入文本框的代码版本:
Dim oProcess As New Process()
Dim oStartInfo As New ProcessStartInfo("ApplicationName.exe", "arguments")
oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oProcess.StartInfo = oStartInfo
oProcess.Start()
Dim sOutput As String
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
sOutput = oStreamReader.ReadToEnd()
End Using
txtOutput.Text = sOutput 'txtOutput being the output textbox.
【讨论】:
我希望这会有所帮助。
Dim proc As New Process
proc.StartInfo.FileName = "C:\ipconfig.bat"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
proc.WaitForExit()
Dim output() As String = proc.StandardOutput.ReadToEnd.Split(CChar(vbLf))
For Each ln As String In output
RichTextBox1.AppendText(ln & vbNewLine)
lstScan.Items.Add(ln & vbNewLine)
Next
'批量创建文件2行如下图:
回声 ipconfig
' 将此文件保存为 ipconfig.bat 或您想要的任何名称。 ' 如果你不想这样,你可以在那里使用任何命令:
回声 目录/秒
或
回声 光盘\ 目录/秒 暂停
【讨论】: