prefect_shell.commands
Tasks for interacting with shell commands
Functions
shell_run_command
command: Shell command to be executed; can also be provided post-initialization by calling this task instance.env: Dictionary of environment variables to use for the subprocess; can also be provided at runtime.helper_command: String representing a shell command, which will be executed prior to thecommandin the same process. Can be used to change directories, define helper functions, etc. for different commands in a flow.shell: Shell to run the command with.extension: File extension to be appended to the command to be executed.return_all: Whether this task should return all lines of stdout as a list, or just the last line as a string.stream_level: The logging level of the stream; defaults to 20 equivalent tologging.INFO.cwd: The working directory context the command will be executed within
- If return all, returns all lines as a list; else the last line as a string.
Classes
ShellProcess
A class representing a shell process.
Supports both async (anyio.abc.Process) and sync (subprocess.Popen) processes.
Methods:
afetch_result
- The lines output from the shell operation as a list.
await_for_completion
fetch_result
- The lines output from the shell operation as a list.
pid
- The PID of the process.
return_code
- The return code of the process, or
Noneif the process is still running.
wait_for_completion
ShellOperation
A block representing a shell operation, containing multiple commands.
For long-lasting operations, use the trigger method and utilize the block as a
context manager for automatic closure of processes when context is exited.
If not, manually call the close method to close processes.
For short-lasting operations, use the run method. Context is automatically managed
with this method.
Attributes:
commands: A list of commands to execute sequentially.stream_output: Whether to stream output.env: A dictionary of environment variables to set for the shell operation.working_dir: The working directory context the commands will be executed within.shell: The shell to use to execute the commands.extension: The extension to use for the temporary file. if unset defaults to.ps1on Windows and.shon other platforms.
aclose
arun
trigger method instead.
Args:
**open_kwargs: Additional keyword arguments to pass toopen_process.
- The lines output from the shell command as a list.
atrigger
run method instead.
Args:
**open_kwargs: Additional keyword arguments to pass toopen_process.
- A
ShellProcessobject.
close
run
trigger method instead.
Args:
**open_kwargs: Additional keyword arguments to pass to subprocess.Popen.
- The lines output from the shell command as a list.
trigger
run method instead.
Args:
**open_kwargs: Additional keyword arguments to pass to subprocess.Popen.
- A
ShellProcessobject.