Learn Before
Concept
Redirection
sh can redirect the STDOUT and STDERR of a process to many different types of targets, using the _out and _err special kwargs. There are two instances:
- Filename: if a string is used, it is assumed to be a filename.
import sh sh.ifconfig(_out="/tmp/interfaces")
- File-like Object: any object that supports .write(data) can be used as well.
import sh from io import StringIO buf = StringIO() sh.ifconfig(_out=buf) print(buf.getvalue())
0
1
Updated 2021-07-20
Tags
Python Programming Language
Data Science