[sos-devel] [PATCH 1/2][sos] Enable sos_get_command() to get input from caller function

Ankit Kumar ankit at linux.vnet.ibm.com
Tue May 9 04:51:05 UTC 2017


This patch enables sos_get_command() to get input data from caller
function using pipe. By default input is NULL and hence it won't
break exiting call and expected behavior.
It also allows caller to provide input through pipe, which helps when we
want to provide mutiple command through pipe.

Signed-off-by: Ankit Kumar <ankit at linux.vnet.ibm.com>
---
 sos/utilities.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sos/utilities.py b/sos/utilities.py
index af60f82..e188e1f 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -110,7 +110,7 @@ def is_executable(command):
 
 
 def sos_get_command_output(command, timeout=300, stderr=False,
-                           chroot=None, chdir=None, env=None):
+                           chroot=None, chdir=None, env=None, input=None):
     """Execute a command and return a dictionary of status and output,
     optionally changing root or current working directory before
     executing command.
@@ -149,10 +149,11 @@ def sos_get_command_output(command, timeout=300, stderr=False,
             expanded_args.append(arg)
     try:
         p = Popen(expanded_args, shell=False, stdout=PIPE,
+                  stdin=PIPE if input else None,
                   stderr=STDOUT if stderr else PIPE,
                   bufsize=-1, env=cmd_env, close_fds=True,
                   preexec_fn=_child_prep_fn)
-        stdout, stderr = p.communicate()
+        stdout, stderr = p.communicate(input)
     except OSError as e:
         if e.errno == errno.ENOENT:
             return {'status': 127, 'output': ""}
-- 
2.7.4




More information about the sos-devel mailing list