Last active
December 9, 2020 09:30
-
-
Save EkkoG/351557e6e465c12986419ac5a4dd2568 to your computer and use it in GitHub Desktop.
A snippet code to call pipeline command line in Python programming language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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