scitex_core.sh
- scitex_core.sh.sh(command_str_or_list, verbose=True, return_as='dict', timeout=None, stream_output=False)[source]
Executes a shell command safely (list format only).
Parameters: - command_str_or_list: Command to execute (MUST be list format) - verbose: Whether to print command and output - return_as: Return format (“dict” or “str”) - timeout: Timeout in seconds (None for no timeout) - stream_output: Whether to stream output in real-time (default: False)
Returns: - If return_as=”str”: output string - If return_as=”dict”: ShellResult dict
Security Notes: - Only list format is allowed to prevent shell injection - Each argument is treated as a literal string - For pipes/redirects, use Python subprocess chaining
- Return type:
Union[str,ShellResult]
Examples:
>>> from scitex.sh import sh >>> sh(["ls", "-la", "/home"]) >>> sh(["git", "status"]) >>> sh(["sleep", "10"], timeout=5) # Will timeout after 5 seconds >>> sh(["./compile.sh"], stream_output=True) # Stream output in real-time >>> >>> # For grep-like filtering, use Python: >>> result = sh(["ls", "-la"]) >>> filtered = [l for l in result['stdout'].split('\n') if '.py' in l]
- scitex_core.sh.sh_run(command, verbose=True)[source]
Executes a shell command and returns detailed results.
Parameters: - command: Command to execute (MUST be list format) - verbose: Whether to print command and output
Returns: - ShellResult dict with stdout, stderr, exit_code, success
- Return type:
ShellResult
Examples:
>>> from scitex.sh import sh_run >>> result = sh_run(["ls", "-la"]) >>> if result['success']: ... print(result['stdout'])