Skip to content

Instantly share code, notes, and snippets.

@EkkoG
Last active December 9, 2020 09:30
Show Gist options
  • Select an option

  • Save EkkoG/351557e6e465c12986419ac5a4dd2568 to your computer and use it in GitHub Desktop.

Select an option

Save EkkoG/351557e6e465c12986419ac5a4dd2568 to your computer and use it in GitHub Desktop.
A snippet code to call pipeline command line in Python programming language
import subprocess
def _call(c, stdin=subprocess.PIPE):
command = subprocess.Popen(c,
stdin = stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return command.stdout, command.stderr, command
def call(*iterables):
first_cmd = iterables[0]
out, err, c = _call(first_cmd)
if len(iterables) == 1:
final_out, final_err = c.communicate()
return (final_out.decode('utf-8'), final_err.decode('utf-8'))
for c in iterables[1:]:
out, err, c = _call(c, out)
final_out, final_err = c.communicate()
return (final_out.decode('utf-8'), final_err.decode('utf-8'))
out, err = call(['ps', '-ef',], ['grep', 'ipfs'], ['grep', 'a'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment