mltk.utils.shell_cmd

Shell command utility

See the source code on Github: mltk/utils/shell_cmd.py

Functions

run_shell_cmd(cmd[, cwd, env, outfile, ...])

Issue shell command

run_shell_cmd(cmd, cwd=None, env=None, outfile=None, line_processor=None, logger=None)[source]

Issue shell command

Parameters:
  • cmd (Union[str, Iterable]) – The shell command. This may be a string or a list of strings

  • cwd (str) – A path to a directory to change to before executing. If omitted then use the current working directory

  • env (dict) – Dictionary of environment variables. If omitted then use current environment variables

  • outfile (IO) – An opened, file-like object to write the shell command’s output

  • line_processor (Callable[[str], str]) – Callback to be invoked for each line returned by shell command

  • logger (Logger) – Logger to dump shell command output

Return type:

Tuple[int, str]

Returns:

(retcode, retmsg)