向/从命令提示符发送和接收消息

时间:2015-06-26 10:37:31

标签: vb.net

我正在使用VB 2010.我的问题是:

我可以在文本框中发送和显示发送的命令,没有任何问题 但是当我尝试在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 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

但是当我使用我的程序时,我得到了

Microsoft Windows [version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. Tous droits r‚serv‚s.

C:\Users\badro@istambul\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\bin\Debug>fastboot 

C:\Users\badro@istambul\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\bin\Debug>exit

1 个答案:

答案 0 :(得分:0)

通过错误流显示没有参数运行时jQuery(function(){ "use strict"; $("#services h2").text("Hello World"); )}; 的语法输出;使用RedirectStandardError来捕捉这个;

fastboot.exe