From 0e80efe63a17ec3e09c232474270a320f57ec222 Mon Sep 17 00:00:00 2001 From: Leohearts Date: Mon, 23 Mar 2026 04:09:58 +0800 Subject: [PATCH] Refactor command execution handling in llm_cmd.py Signed-off-by: Leohearts --- llm_cmd.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/llm_cmd.py b/llm_cmd.py index 33b9d33..a672251 100644 --- a/llm_cmd.py +++ b/llm_cmd.py @@ -1,6 +1,9 @@ import click import llm import subprocess +import os +import sys +import platform from prompt_toolkit import PromptSession from prompt_toolkit.lexers import PygmentsLexer from prompt_toolkit.patch_stdout import patch_stdout @@ -40,10 +43,13 @@ def interactive_exec(command): edited_command = session.prompt("> ", default=command, multiline=True) else: edited_command = session.prompt("> ", default=command) - try: - output = subprocess.check_output( - edited_command, shell=True, stderr=subprocess.STDOUT - ) - print(output.decode()) - except subprocess.CalledProcessError as e: - print(f"Command failed with error (exit status {e.returncode}): {e.output.decode()}") \ No newline at end of file + if hasattr(sys.stdin, 'isatty') and sys.stdin.isatty(): + os.system(edited_command) + else: + try: + output = subprocess.check_output( + edited_command, shell=True, stderr=subprocess.STDOUT + ) + print(output.decode()) + except subprocess.CalledProcessError as e: + print(f"Command failed with error (exit status {e.returncode}): {e.output.decode()}")