Partilhar via


CommandWindow.SendInput(String, Boolean) Method

Definition

Sends a line of input to the Command window that is processed as if you typed it.

public:
 void SendInput(System::String ^ Command, bool Execute);
public:
 void SendInput(Platform::String ^ Command, bool Execute);
void SendInput(std::wstring const & Command, bool Execute);
[System.Runtime.InteropServices.DispId(3)]
public void SendInput (string Command, bool Execute);
[<System.Runtime.InteropServices.DispId(3)>]
abstract member SendInput : string * bool -> unit
Public Sub SendInput (Command As String, Execute As Boolean)

Parameters

Command
String

Required. The command string to send to the Command window.

Execute
Boolean

Required. True means, add a newline character and execute the line of input, False means, do not execute the command line.

Attributes

Examples

Sub CommandWinExample(ByVal dte As DTE)  
    ' Get a reference to the Command window.  
    Dim win As Window = _  
    DTE.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow)  
    Dim CW As CommandWindow = win.Object  

    ' Input a command into the Command window and execute it.  
    CW.SendInput("nav http://www.microsoft.com", True)  

    ' Insert some information text into the Command window.  
    CW.OutputString("This URL takes you to the main Microsoft _  
    website.")  

    ' Clear the contents of the Command window.  
    MsgBox("Clearing the Command window...")  
    CW.Clear()  
End Sub  
void CommandWinExample(_DTE dte)   
{  
    // Get a reference to the Command window.  
    Window win =      
    dte.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow);  
    CommandWindow CW = (CommandWindow)win.Object;  

    // Input a command into the Command window and execute it.  
    CW.SendInput("nav http://www.microsoft.com", true);  

    // Insert some information text into the Command window.  
    CW.OutputString("This URL takes you to the main Microsoft   
    website.");  

    // Clear the contents of the Command window.  
    MessageBox.Show("Clearing the Command window...");  
    CW.Clear();  
}  

Remarks

If the value of Execute is true, SendInput automatically runs the command. Otherwise, you must press ENTER in the Command window to run it. You can construct a command line by repeatedly calling this method. You can then execute it by setting Execute to true on the final call.

You can use SendInput to accumulate multiple lines of input and then execute them whenever you want. This differs from the ExecuteCommand method, which executes instructions immediately after you provide the input string. SendInput is useful if you want to create complex command lines by manually entering distinct aspects of the command line. In addition, when you use SendInput, you can view any output generated by the command. When you use ExecuteCommand, you do not see any output, and you must construct a complete command line in your line of input.

Applies to