Here are my notes from starting to use and learn the python programming language. I am only focusing on Python 3 at this time.
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.
Some key points:
args=[cmd, '-I', 'lanplus', '-H', BMC_IP, “-U”, User_Name, '-f', PW_file_location, 'power', power_ctl]
, where components in quotation are text and those without are variables.shell=False
must be set. This is the default default and preferred option.stdout=subprocess.PIPE
In order to capture the command output from the function. Otherwise it will go to the standard output stream, e.g. the terminal screen.subprocess.stdout
, this is in byte format. subprocess.stdout.decode('utf-8')
subprocess.returncode
My python based back-up scripts are located here: python_backup_scripts