Shell
Class Shell

The Shell class provides simple access to the Unix/Linux or Windows shell. You can execute a shell command, and then retrieve the result and/or error code.

The following methods require a Shell instance:

Method PrototypeDescription
Sub Constructor()initialize the Shell object
Dim SafeMode As Booleanget/set whether arguments should be escaped (defaults to True)
Function ErrorCode() As Integerget the shell process error code, if any
Sub Execute(command As String, arguments As String="")execute the given command (optionally, with arguments)
Function Result() As Stringget the result of the last Execute call
Function TimeOut() As Integerget the number of seconds the shell will wait before timing out
Sub TimeOut(Assigns newValue As Integer)set the number of seconds the shell will wait before timing out


The following shared methods can be called without a specific instance, just using the "Shell." prefix:

Method PrototypeDescription
Shared Function EscapeArgument(arg as String) As Stringescape an argument for shell security
Shared Function EscapeCmd(command as String) As Stringescape a command for shell security
Shared Function Execute(command As String, arguments As String="") As Stringexecute a shell command (in safe mode) and get the result


Yuma's Shell class supports a "safe mode," which escapes special characters from the command or arguments before passing them onto the shell. This is an important security feature, as if malicious users find any way to inject those characters into a shell call (for example, because your web app prompts them for a file name and then passes that on to a shell command), they might be able to execute arbitrary shell commands. So it is highly recommended to leave SafeMode set to True.

For simple needs, you don't actually need to instantiate Shell at all; just call Shell.Execute instead, which returns the result as a string. If you need more control over the call, such as adjusting the TimeOut value, avoiding safe mode, or retrieving the error code, then create a Shell object and use that instead.