Used to execute Unix or DOS shell commands under Windows, OS X, or Linux.
Use the Shell class to execute DOS or Unix commands and get the results. The Execute method executes a one-line command in Synchronous mode. This causes two properties of the Shell object to change: ErrorCode, which is a system-supplied error code or 0 for no error; and Result, which is a string containing the output of the command. The TimeOut property specifies how long (in milliseconds) a process can run before it is automatically terminated. A value of -1 means the process can run indefinitely. This property currently applies only to Windows.
The process running in the Shell is killed when the object gets out of scope even if running in asynchronous mode (Mode = 1 or 2).
The Shell is not equivalent to the Terminal or Command app for your OS. Paths and other default settings will likely not be the same. If you need to do configuration of the Shell before you use it, be sure to set it up to be interactive so you can set up the configuration before calling other shell commands.
Shell Differences on Windows
It appears that some Windows shell commands such as ftp or telnet will not work as expected.
See this post to learn about shell differences on Windows.
Using the synchronous mode, the following code lists the current directory's files using the dir command on Windows and ls on Mac OS X and Linux.
s = New Shell
#If TargetWin32 Then
#Elseif TargetMacOS Or TargetLinux Then
If s.ErrorCode = 0 Then
TextField1.Text = s.Result
MsgBox("Error code: " + Str(s.ErrorCode))
The following example gets the names and values of the environment variables on the user's computer and displays the information in a TextField. You can use the EnvironmentVariable method of the System module to get or set individual environment variables.
Dim cmd As String
#If TargetMacOS Or TargetLinux Then
cmd = "env"
#Elseif TargetWin32 Then
cmd = "set"
If s.ErrorCode=0 Then
TextField1.Text = s.Result
TextField1.Text = "Error " + Str(s.ErrorCode)
The following terminal application allows you to submit Unix commands using the interactive mode. The interface consists of two TextFields, 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).
mShell.Mode = 2
The user can type a unix command into the TextField, InputField. When he presses Return, the following code in the TextField's KeyDown event runs. The Write method sends the command to the Shell's input buffer.
If Not mShell.IsRunning Then
InputField.Text = ""
A Timer calls the ReadAll method in its Action event and displays the output in OutputField:
Dim output As String = mShell.ReadAll
If output <> "" Then
OutputField.SelText = output