hplip/hplip-plugin-stdout.patch
2026-01-09 13:04:20 +01:00

41 lines
1.8 KiB
Diff

diff --git a/base/os_utils.py b/base/os_utils.py
index 82a8b42..d918822 100644
--- a/base/os_utils.py
+++ b/base/os_utils.py
@@ -26,6 +26,7 @@ import locale
import stat
import subprocess
import shlex
+import sys
#Local
from . import logger
@@ -37,17 +38,22 @@ def execute(cmd):
try:
# Use shlex.split to safely split the command into arguments
args = shlex.split(cmd)
- process = subprocess.Popen(args,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ process = subprocess.Popen(args,stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin)
process.wait()
stdout, stderr = process.communicate()
- log.debug(f"Command executed: {cmd}\n{stdout.decode()}")
+
+ log.debug(f"Command executed: {cmd}{f'\n{stdout.decode()}' if stdout else ''}")
+
if process.returncode != 0:
- error_message = f"Command failed with return code {process.returncode}: {cmd}\n{stderr.decode()}"
- log.error(error_message)
+ log.error(f"Command failed with return code" \
+ f"{process.returncode}: {cmd}" \
+ f"{f'\n{stderr.decode()}' if stderr else ''}")
+
return process.returncode
except subprocess.CalledProcessError as e:
- error_message = f"Command failed with return code {e.returncode}: {cmd}\n{e.stderr.decode()}"
- log.error(error_message)
+ log.error(f"Command failed with return code" \
+ f"{e.returncode}: {cmd}" \
+ f"{f'\n{e.stderr.decode()}' if e.stderr else ''}")
return e.returncode
except Exception as e:
log.error(f"Error executing command: {cmd}\n{str(e)}")