diff options
author | Christian Breunig <christian@breunig.cc> | 2023-01-16 18:09:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-16 18:09:42 +0100 |
commit | a3b1ffb4f4d71a3de3baa54bb08474951efc281e (patch) | |
tree | 3162826312e442daa5ef8190148dac1ea914b713 | |
parent | 598dcad7237d49861ca6216deea254b7c942241f (diff) | |
parent | a0b0670f46128b0be657e50b5751d23b5f602373 (diff) | |
download | vyos-1x-a3b1ffb4f4d71a3de3baa54bb08474951efc281e.tar.gz vyos-1x-a3b1ffb4f4d71a3de3baa54bb08474951efc281e.zip |
Merge pull request #1759 from sever-sever/T4575
vyos.util: T4575: Add new wrapper "rc_cmd"
-rw-r--r-- | python/vyos/util.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 67ec3ecc6..5c6409341 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -164,6 +164,27 @@ def cmd(command, flag='', shell=None, input=None, timeout=None, env=None, return decoded +def rc_cmd(command, flag='', shell=None, input=None, timeout=None, env=None, + stdout=PIPE, stderr=STDOUT, decode='utf-8'): + """ + A wrapper around popen, which returns the return code + of a command and stdout + + % rc_cmd('uname') + (0, 'Linux') + % rc_cmd('ip link show dev eth99') + (1, 'Device "eth99" does not exist.') + """ + out, code = popen( + command, flag, + stdout=stdout, stderr=stderr, + input=input, timeout=timeout, + env=env, shell=shell, + decode=decode, + ) + return code, out + + def call(command, flag='', shell=None, input=None, timeout=None, env=None, stdout=PIPE, stderr=PIPE, decode='utf-8'): """ |