# Shell Tasks
# ShellTask
class
prefect.tasks.shell.ShellTask
(command=None, env=None, helper_script=None, shell="bash", return_all=False, log_stderr=False, stream_output=False, **kwargs)[source]Task for running arbitrary shell commands.
NOTE: This task combines stderr and stdout because reading from both streams without blocking is tricky.
Args:
command (string, optional): shell command to be executed; can also be provided post-initialization by calling this task instanceenv (dict, optional): dictionary of environment variables to use for the subprocess; can also be provided at runtimehelper_script (str, optional): a string representing a shell script, which will be executed prior to thecommandin the same process. Can be used to change directories, define helper functions, etc. when re-using this Task for different commands in a Flow; can also be provided at runtimeshell (string, optional): shell to run the command with; defaults to "bash"return_all (bool, optional): boolean specifying whether this task should return all lines of stdout as a list, or just the last line as a string; defaults toFalselog_stderr (bool, optional): boolean specifying whether this task should log the output in the case of a non-zero exit code; defaults toFalse. This actually logs both stderr and stdout and will only log the last line of output unlessreturn_allisTruestream_output (Union[bool, int, str], optional): specifies whether this task should log the output as it occurs, and at what logging level. IfTrueis passed, the logging level defaults toINFO; otherwise, any integer or string value that's passed will be treated as the log level, provided thelogginglibrary can successfully interpret it. If enabled,log_stderrwill be ignored as the output will have already been logged. defaults toFalse**kwargs: additional keyword arguments to pass to the Task constructor
TypeError: ifstream_outputis passed in as a string, but cannot successfully be converted to a numeric value by logging.getLevelName()
    from prefect import Flow
    from prefect.tasks.shell import ShellTask
    task = ShellTask(helper_script="cd ~")
    with Flow("My Flow") as f:
        # both tasks will be executed in home directory
        contents = task(command='ls')
        mv_file = task(command='mv .vimrc /.vimrc')
    out = f.run()
| methods: | 
|---|
prefect.tasks.shell.ShellTask.run (command=None, env=None, helper_script=None)[source] | 
Run the shell command. 
 
 
  | 
This documentation was auto-generated from commit n/a 
on February 23, 2022 at 19:26 UTC