demo_utils.shell module¶
Run Shell commands through python
- Usage:
1 2 3 4 5 6 7 8
from demo_utils.shell import Shell sh = Shell() sh.run('ls') sh.set_cwd('~') sh.set_cwd('/') sh.run('ls')
-
class
demo_utils.shell.
Shell
(wd='')¶ -
run
(command, args='')¶ Run shell commands
Parameters: - command (str) – command to run. You can add arguments afterwards
- args (list, optional) – a list of string arguments which will be joined by spaces. Below is the implementation:
if len(args) > 0: command = ' '.join([command, args.join(' ')])
Returns: The output from subprocess.Popen
. This is a 2 element list of strings- [0] - stdout
- [1] - stderr
Return type: list
-
set_cwd
(new_cwd)¶ Set the current Working directory for the shell.
cd
doesn’t work because we don’t persist the subprocess between calls.When setting the working directory we are simply setting the
cwd
argument insubprocess.Popen
.Returns: N/A Raises: IOError
– Raised when the directory we try to set doesn’t exist.
-