Vb.net 向命令提示符发送和从命令提示符接收消息
我正在使用VB 2010。我的问题是: 我可以在文本框中发送和显示send命令,没有任何问题 但是当我尝试在cmd中使用另一个.exe时,我无法在文本框中显示它 我的源代码是:Vb.net 向命令提示符发送和从命令提示符接收消息,vb.net,Vb.net,我正在使用VB 2010。我的问题是: 我可以在文本框中发送和显示send命令,没有任何问题 但是当我尝试在cmd中使用另一个.exe时,我无法在文本框中显示它 我的源代码是: Private Results As String 'The "Delegate" is used to correct the threading issue (Can't update control directly in VB.net 08/10), and invokes the needed te
Private Results As String
'The "Delegate" is used to correct the threading issue (Can't update control directly in VB.net 08/10), and invokes the needed text update.
Private Delegate Sub delUpdate()
Private Finished As New delUpdate(AddressOf UpdateText)
Private Sub UpdateText()
TextBox2.Text = Results
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub CMDAutomate()
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
'Starts the CMD Prompt
StartInfo.FileName = "cmd.exe"
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
'Required to redirect
StartInfo.UseShellExecute = False
'Disables the creation of a CMD Prompt outside application.
StartInfo.CreateNoWindow = True
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
'Runs the command you entered...
SW.WriteLine(TextBox1.Text)
'Exits CMD Prompt
SW.WriteLine("exit")
'Displayes the results...
Results = SR.ReadToEnd
SW.Close()
SR.Close()
'Invokes Finished delegate, which updates textbox with the results text
Invoke(Finished)
End Sub
End Class
例如,当我在cmd上使用命令fastboot
时,我得到
usage: fastboot [ <option> ] <command>
commands:
update <filename> reflash device from update.zip
flashall flash boot + recovery + system
flash <partition> [ <filename> ] write a file to a flash partition
erase <partition> erase a flash partition
format <partition> format a flash partition
getvar <variable> display a bootloader variable
boot <kernel> [ <ramdisk> ] download and boot kernel
flash:raw boot <kernel> [ <ramdisk> ] create bootimage and flash it
devices list all connected devices
continue continue with autoboot
reboot reboot device normally
reboot-bootloader reboot device into bootloader
help show this help message
options:
-w erase userdata and cache (and format
if supported by partition type)
-u do not first erase partition before
formatting
-s <specific device> specify device serial number
or path to device port
-l with "devices", lists device paths
-p <product> specify product name
-c <cmdline> override kernel commandline
-i <vendor id> specify a custom USB vendor id
-b <base_addr> specify a custom kernel base address
-n <page size> specify the nand page size. default:
2048
-S <size>[K|M|G] automatically sparse files greater th
an
size. 0 to disable
在没有参数的情况下运行时,
fastboot.exe
的语法输出通过错误流显示;用于捕获此信息
StartInfo.RedirectStandardError = True
Dim SE As System.IO.StreamReader = myprocess.StandardError
Uni exception de première chance de type'System.InvalidOperationException's's's produite dans System.d使用您的代码(尽管在我的测试用例中运行了一些更改),这对我来说很好。您是否以与StandardOutput相同的方式实现它?“禁用在应用程序外部创建CMD提示符。StartInfo.CreateNoWindow=True StartInfo.RedirectStandardError=True myprocess.StartInfo=StartInfo myprocess.Start()Dim SR As System.IO.StreamReader=myprocess.StandardOutput Dim SW As System.IO.StreamWriter=myprocess.StandardInput Dim SE As System.IO.StreamReader=myprocess.StandardError
StartInfo.RedirectStandardError = True
Dim SE As System.IO.StreamReader = myprocess.StandardError