I’m trying to figure out a neat solution to this problem I have in Python.
From Python I’d like to issue the following (for example):
import subprocess
result = subprocess.run(["ls"], shell=True, capture_output=True, text=True)
print(result.stdout)
- Then extending ‘ls’ command with a few arguments i.e. ‘ls *.txt’.
- Also other commands i.e ‘ps -ef’ with a selection of arguments.
- Sometimes I want the response from the command, and sometimes not.
I’m looking for a Design Pattern that allows me to issue a variety Unix commands with/without arguments sometimes interested in the response and sometimes not (depending up on the command)
At the moment I just have a 25+ ‘subprocess.run()’ in one Python file.