re: Python Linux Command executor VIEW POST

FULL DISCUSSION
 

Hi muTheTechie, I think you can simplify the error checking like this:

def cmdExecutor(cliCmd):
    cmd = shlex.split(cliCmd)
    process, error = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
    print("Command executed successfully")
    if error:
      return f"ERROR => {error.decode('utf-8')}"
    else:
      return "SUCCESS"

you don't need to convert the error to a string

 
code of conduct - report abuse