Python Programming Notes

Back  
 Next

Python Programming Notes

Here are my notes from starting to use and learn the python programming language. I am only focusing on Python 3 at this time.

subprocess module

The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.
Some key points:

  • The command to be run arguments “args” should be passed in as a list, the list components should not contain any white space. e.g.:
    • 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.
    • With argument type the input option 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.
    • the output value can be captured from subprocess.stdout, this is in byte format.
    • It can be captured and converted to text format subprocess.stdout.decode('utf-8')
    • The return code of the function can be capture from output using subprocess.returncode

Python Back-up Scripts

My python based back-up scripts are located here: python_backup_scripts

Some on line resources

/app/www/public/data/pages/python/subprocess.txt · Last modified: 2023-12-26 Tue wk52 11:47
CC Attribution-Share Alike 4.0 International Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International