Python Module subprocess: Difference between revisions
Jump to navigation
Jump to search
Line 20: | Line 20: | ||
<font color=darkkhaki>TO PROCESS: https://janakiev.com/blog/python-shell-commands/</font> | <font color=darkkhaki>TO PROCESS: https://janakiev.com/blog/python-shell-commands/</font> | ||
=<tt>subprocess.run()</tt>= | |||
<syntaxhighlight lang='py'> | |||
import subprocess | |||
completed_process = subprocess.run( | |||
'ls', | |||
capture_output=True, | |||
check=True, | |||
shell=True, | |||
) | |||
print(completed_process.stdout) | |||
</syntaxhighlight> |
Latest revision as of 03:43, 8 September 2022
External
Internal
Overview
Execute an O/S Command
import subprocess
helm = subprocess.Popen(['helm', 'package', './my-chart'],
cwd = str(Path(project_dir, 'build/helm')),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
stdout, stderr = helm.communicate()
print(stdout)
print(stderr)
Need standard failure handling patter.
TO PROCESS: https://janakiev.com/blog/python-shell-commands/
subprocess.run()
import subprocess
completed_process = subprocess.run(
'ls',
capture_output=True,
check=True,
shell=True,
)
print(completed_process.stdout)