subprocess
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions:
os.system
os.spawn*
https://docs.python.org/3/library/subprocess.html
https://docs.python.org/ja/3/library/subprocess.html (in Japanese)
code:python
subprocess.run("ls", "-l")
code:python
p = subprocess.Popen('sh', 'cmdsample.sh',
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
print 'return: %d' % (p.wait(), )
print 'stdout: %s' % (p.stdout.readlines(), )
print 'stderr: %s' % (p.stderr.readlines(), )
python - subprocess wildcard usage - Stack Overflow
https://stackoverflow.com/questions/9997048/subprocess-wildcard-usage
Tips
How To Abstract SSH Commands in Python
https://betterprogramming.pub/how-to-run-ssh-commands-with-python-8111ee8ab405
#SSH
Bash vs. Python vs. JavaScript: Which Is Better for Automation? | by Shalitha Suranga | Oct, 2021 | Better Programming
https://betterprogramming.pub/bash-vs-python-vs-javascript-which-is-better-for-automation-92a277ef49e
check output
code:pyhon
#!/usr/bin/python3
import subprocess
o = subprocess.check_output('node', '--version', text = True)
print('You are using Node ' + o)
【Python入門】subprocessを使ってコマンドを実行しよう! | 侍エンジニアブログ
Python の subprocess で出力を受け取るときは communicate() を使おう #Python - Qiita