diff options
Diffstat (limited to 'src/linux/ogOperations.py')
-rw-r--r-- | src/linux/ogOperations.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py index bbce41a..5813cf7 100644 --- a/src/linux/ogOperations.py +++ b/src/linux/ogOperations.py @@ -7,9 +7,9 @@ # (at your option) any later version. import os +import shlex import psutil import subprocess -from subprocess import CalledProcessError from src.log import OgError from src.ogRest import ThreadState @@ -30,20 +30,22 @@ class OgLinuxOperations: def shellrun(self, request, ogRest): cmd = request.getrun() + is_inline = request.get_inline() + + if not is_inline: + raise OgError("Only inline mode is supported on Linux") + try: - result = subprocess.run(cmd, - shell=True, - stdin=subprocess.DEVNULL, - capture_output=True, - text=True, - check=True) - except CalledProcessError as error: - if error.stderr: - return error.stderr - if error.stdout: - return error.stdout - return "{Non zero exit code and empty output}" - return result.stdout + ogRest.proc = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + shell=True) + (output, error) = ogRest.proc.communicate() + except (OSError, subprocess.SubprocessError) as e: + raise OgError(f'Error when running "shell run" subprocess: {e}') from e + + output = output.decode('utf-8-sig', errors='replace') + return (ogRest.proc.returncode, cmd, output) def session(self, request, ogRest): raise OgError('Function not implemented') |