Python

Execute shell command

from subprocess import run, CalledProcessError
  try:
    run(["echo", ["..."]], capture_output=True, text=True, check=True, shell=True)
  except CalledProcessError as error:
	pass
  • The first argument is a list[str] with argument separated. shlex.split("my cmd") can be used to get the array. If it's used with the shell=True, the argument must be ["all you command in one place"].
  • capture_output=True asks to get the output
  • text=True requires the stdout & stderr to be str
  • shell=True execute the command as a shell command. Use with cautious and not when using external inputs!

Good libraries

  • Rich: library to create a format text into the terminal
  • Mkdocs: create a documentation
  • Xml2rfc: transform an xml document into an rfc format, see docs and writting