我正在通过VB.net开发一个项目,我正在使用CMD来执行命令我想知道如何将CMD的结果复制到我主表单上的文本框中
答案 0 :(得分:1)
在这里查看接受的答案: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.
答案 1 :(得分:-1)
我希望这会有所帮助。
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或您想要的任何名称。 '如果你不想要你可以在那里使用任何命令:
回声 DIR / S或
回声 光盘\ DIR / S 暂停