Commits

Thomas Waldmann committed 0694580 Draft

add exec_cmd (based on popen/communicate)

Comments (0)

Files changed (1)

+# -*- coding: ascii
+"""
+execute (shell or other) commands
+
+author: Thomas Waldmann
+license: BSD
+"""
+
+import subprocess
+
+
+def exec_cmd(cmd, input=None):
+    p = subprocess.Popen(cmd, shell=True,
+                        close_fds=not subprocess.mswindows,
+                        bufsize=1024,
+                        stdin=subprocess.PIPE,
+                        stdout=subprocess.PIPE,
+                        stderr=subprocess.PIPE)
+    data, errors = p.communicate(input)
+    return data, errors, p.returncode
+