meta data for this page
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| programming:python:run_system_command [2024/02/10 09:36] – created niziak | programming:python:run_system_command [2024/02/23 08:46] (current) – niziak | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== system / popen / exec ====== | ||
| + | In general: run system commands. | ||
| + | |||
| + | Current recommended way is to use [[https:// | ||
| + | <code python> | ||
| + | os.system | ||
| + | os.spawn* | ||
| + | </ | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | Features: | ||
| + | * possible to execute in shell: | ||
| + | * all command and params can be specified as string not list | ||
| + | * multiple commands can be executed at once; shell pipes usage possible | ||
| + | * configurable check for return codes or output | ||
| + | |||
| + | Parameters: | ||
| + | * [[https:// | ||
| + | * | ||
| + | |||
| + | Examples: | ||
| <code python> | <code python> | ||
| Line 6: | Line 30: | ||
| return output.communicate()[0].decode(" | return output.communicate()[0].decode(" | ||
| </ | </ | ||
| + | |||
| + | see [[programming: | ||
| + | |||
| + | <code python> | ||
| + | import subprocess | ||
| + | meta_data = subprocess.check_output([' | ||
| + | data = meta_data.decode(' | ||
| + | </ | ||
| + | |||
| + | <code python> | ||
| + | return subprocess.check_output( | ||
| + | [self.FW_PRINTENV, | ||
| + | stderr=subprocess.STDOUT, | ||
| + | ... | ||
| + | return subprocess.check_call([self.FW_SETENV, | ||
| + | </ | ||
| + | |||