Skip to content

Instantly share code, notes, and snippets.

@ACK-J
Created October 2, 2020 16:08
Show Gist options
  • Save ACK-J/07b8bda1984ff5feb1fa6d984b4dea21 to your computer and use it in GitHub Desktop.
Save ACK-J/07b8bda1984ff5feb1fa6d984b4dea21 to your computer and use it in GitHub Desktop.
A function which can make a syscall in python and return stdout, stderr and the return-code
import subprocess
def runcommand(cmd):
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
universal_newlines=True)
std_out, std_err = proc.communicate()
return proc.returncode, std_out, std_err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment