ShellProxy
Proxy for executing shell commands with advanced output handling and logging.
This class provides a high-level interface for running shell commands in a subprocess with features including:
- Real-time output dispatching to message observers
- Environment variable management
- Working directory control
- Both blocking and non-blocking execution modes
- Integration with progress bars and message dispatchers
The proxy can be used as a context manager for automatic cleanup of temporary directories.
Logging Format Support
When using ShellProxy with a message_dispatcher (e.g., in virtual environment agents), the stdout/stderr output supports special format prefixes for message categorization:
[INFO] message- Info message[SUCCESS] message- Success message[WARNING] message- Warning message[ERROR] message- Error message[DEBUG] message- Debug message[PROGRESS:XX] message- Progress message (XX = 0-100)
These format prefixes are automatically parsed by the message_dispatcher to dispatch messages with the appropriate severity level and type. This is particularly useful in virtual environment agents where standard logging methods are not available.
Example:
python # In a virtual environment agent script print("[INFO] Starting processing...") print("[PROGRESS:50] Halfway done...") print("[SUCCESS] Processing completed!")
working_dir: strInitialize a ShellProxy instance.
str | Nonegws_core.core.classes.observer.message_dispatcher.MessageDispatcher | NoneAttach a custom observer to the shell proxy.
The logs of the proxy will be dispatched to the observer.
MessageObserverAttach a progress bar to the shell proxy.
The logs of the proxy will be dispatched to the progress bar logs.
ProgressBarRun a command in a shell and return the output. The logs of the command are ignored.
list | strdict | NoneShellProxyEnvVariableMode - ShellProxyEnvVariableMode.MERGEbool | Nonebool - TrueAnyDelete the working directory and all its contents.
Force the message dispatcher to send all buffered messages immediately.
Get the default environment variables for the shell proxy. To override in subclasses to provide custom additional default environment variables.
dictGet the message dispatcher instance.
MessageDispatcherLog an error message using the dispatcher.
strLog an info message using the dispatcher.
strLog a warning message using the dispatcher.
strRun a command in a shell. The logs of the command will be dispatched to the message dispatcher during the execution.
list | strdict | NoneShellProxyEnvVariableMode - ShellProxyEnvVariableMode.MERGEbool | Nonebool - Falsebool - TrueintRun a command in a shell without blocking the thread. The logs of the command are ignored.
list | strdict | NoneShellProxyEnvVariableMode - ShellProxyEnvVariableMode.MERGEbool | NoneSysProcConvert the ShellProxy instance to a data transfer object.
ShellProxyDTOReturns the name of the class
bool - Falsebool - Falsebool - FalsestrReturns the full name of the class
bool - Falsebool - FalsestrstrVersionGet the human name of the object
strGet the short description of the object
strGet the style of the object
TypingStyleGet the typing name of the object Ex: 'RESOURCE.gws_core.Table'
strTypingNameObjGet all the classes that inherit this class
list