Python Module subprocess: Difference between revisions
Jump to navigation
Jump to search
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
=Execute an O/S Command= | =Execute an O/S Command= | ||
<syntaxhighlight lang='py'> | |||
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) | |||
</syntaxhighlight> | |||
<font color=darkkhaki>Need standard failure handling patter.</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)