我已经创建了一个应用程序,它运行cmd命令并读取cmd中的所有值并将其写入文本框中。它工作得很好,但我想在文本框的每一行前添加特殊字符,这是我的代码:
Imports System.IO
Public Class Form1
Private strResults As String
Private Delegate Sub delRefresh()
Private ShowText As New delRefresh(AddressOf DisplayText)
Private Sub OverrideCMD()
Dim prcDOS As New Process
Dim siDOS As New ProcessStartInfo
siDOS.FileName = "cmd"
siDOS.UseShellExecute = False
siDOS.CreateNoWindow = True
siDOS.RedirectStandardInput = True
siDOS.RedirectStandardOutput = True
prcDOS.StartInfo = siDOS
prcDOS.Start()
Dim srInput As StreamWriter = prcDOS.StandardInput
Dim srOutput As StreamReader = prcDOS.StandardOutput
srInput.WriteLine(txtCommand.Text)
srInput.WriteLine("exit")
strResults = srOutput.ReadToEnd
srInput.Close()
srOutput.Close()
Invoke(ShowText)
End Sub
Private Sub DisplayText()
' show output to textbox
txtResults.Text = strResults
End Sub
' textbox where you place cmd commands to execute and then press enter
Private Sub txtCommand_KeyDown(sender As Object, e As KeyEventArgs) Handles txtCommand.KeyDown
If e.KeyCode = Keys.Enter Then
Dim tOverride As New Threading.Thread(AddressOf OverrideCMD)
tOverride.Start()
End If
End Sub
End Class
结果:
Microsoft Windows [Version 6.1.7601]
版权所有(c)2009 Microsoft Corporation。版权所有。
如何将reult文本转换为:
没有()
(>>)Microsoft Windows [Version 6.1.7601]
(>>)版权所有(c)2009 Microsoft Corporation。保留所有权利。
帮我修复代码..谢谢大师..
答案 0 :(得分:0)
通过观看strResults
,您可以看到行由vbCrLf
字符分隔。
所以你可以改变:
strResults = srOutput.ReadToEnd
以下内容:
strResults = vbCrLf + srOutput.ReadToEnd
strResults = strResults.Replace(vbCrLf, vbCrLf + ">> ")