OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Is there a Design Pattern for issuing command, command + response (both with different arguments)

  • Thread starter Thread starter molko
  • Start date Start date
M

molko

Guest
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):

Code:
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.
<p>I'm trying to figure out a neat solution to this problem I have in Python.</p>
<p>From Python I'd like to issue the following (for example):</p>
<pre><code>import subprocess
result = subprocess.run(["ls"], shell=True, capture_output=True, text=True)
print(result.stdout)
</code></pre>
<ul>
<li>Then extending 'ls' command with a few arguments i.e. 'ls *.txt'.</li>
<li>Also other commands i.e 'ps -ef' with a selection of arguments.</li>
<li>Sometimes I want the response from the command, and sometimes not.</li>
</ul>
<p>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)</p>
<p>At the moment I just have a 25+ 'subprocess.run()' in one Python file.</p>
 
Top