Skip to content

Commit

Permalink
Fix shell command on Python 3 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan authored Nov 27, 2023
1 parent 24624a2 commit 597da45
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions zabbix_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7103,11 +7103,15 @@ def do_shell(self, line):
"""
try:
proc = subprocess.Popen([line], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, errors = proc.communicate()
print(output + errors + '\n')

except Exception:
self.generate_feedback('Error', 'Problems running %s' % line)
out, err = proc.communicate()
output = out.decode("utf-8").strip()
if output:
print(output)
errors = err.decode("utf-8").strip()
if errors:
print(errors, file=sys.stderr)
except Exception as e:
self.generate_feedback('Error', f"Problems running {line}: {e}")

def do_quit(self, args):
"""
Expand Down

0 comments on commit 597da45

Please sign in to comment.