summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-07-29 19:47:36 +0200
committerGitHub <noreply@github.com>2022-07-29 19:47:36 +0200
commit437c73888a4998f791ed0642da65a249425e7cb7 (patch)
treef7fced642102f2981b9540c26d333bca4294f74e
parent516b86bb970c7e039b58e554cb3b22e8f996841f (diff)
parent14418b6d80ef4652a44d9280baf369c8e3c429fd (diff)
downloadvyos-1x-437c73888a4998f791ed0642da65a249425e7cb7.tar.gz
vyos-1x-437c73888a4998f791ed0642da65a249425e7cb7.zip
Merge pull request #1442 from sever-sever/T4575
vyos.util: T4575: Add new wrapper "rc_cmd"
-rw-r--r--python/vyos/util.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index bee5d7aec..b86b1949c 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'):
"""