<div class="meta" robots="noindex">

</div>

Property

# Shell.Mode

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `Shell.ExecuteMode<shell.executemode>` as a replacement.

</div>

## Description

Controls the <span class="title-ref">Mode</span> in which the shell operates. The shell can be running in Synchronous, Asynchronous, or Interactive modes.

## Notes

Here are descriptions of each <span class="title-ref">Mode</span>.

| Value | Name         | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|-------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0     | Synchronous  | (Default) The shell executes its command and returns the result in the Result property when the script has finished running. Synchronous shells block the main UI thread, even when they are in a thread themselves. For long-running shell processes, use one of the other shell modes instead.                                                                                                                                                             |
| 1     | Asynchronous | The shell executes its command and returns data via the `DataAvailable<shell.dataavailable>` event. It does not wait for a command to finish before executing the next command. An asynchronous shell script can run in the background. You'll need to make sure the Shell instance does not go out of scope while you are waiting for operations to complete.                                                                                               |
| 2     | Interactive  | The script can display a prompt and the user can interact with the shell script while it is running. Data can be sent to a running shell session with the Write method and data is returned via the `DataAvailable<shell.dataavailable>` event. Refer the interactive shell Example included with your installation (Advanced/Shell). You'll need to make sure the Shell instance does not go out of scope while you are waiting for operations to complete. |

To access the `DataAvailable<shell.dataavailable>` event handler, you can subclass Shell or use `AddHandler</api/language/addhandler>`.

## Sample code

The following terminal application allows you to submit Unix commands using the interactive <span class="title-ref">Mode</span>. The interface consists of two `TextFields</api/deprecated/textfield>`, InputField, in which the user can enter a command, and OutputField that displays the results.

The Open event for the window initializes the shell object (declared as a property of the window).

``` xojo
mShell = New Shell
mShell.Mode = 2
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The user can type a unix command into the `TextField</api/deprecated/textfield>`, InputField. When they press Return, the following code in the `TextField</api/deprecated/textfield>`'s KeyDown event runs. The Write method sends the command to the Shell's input buffer.

``` xojo
If Key = Chr(13) Then
  If Not mShell.IsRunning Then
    mShell.Execute "sh"
  End If
  mShell.Write(InputField.Text)
  mShell.Write(Chr(13))
  InputField.Text = ""
  Return True
Else
  Return False
End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

A `Timer</api/language/timer>` calls the ReadAll method in its Action event and displays the output in OutputField:

``` xojo
If mShell <> Nil Then
  Dim output As String = mShell.ReadAll
  If output <> "" Then
    OutputField.SelText = output
  End If
End If
```

## Compatibility

All project types on all supported operating systems.
