Command error detection methods, apparatus, devices, storage media, and program products

By obtaining execution status information and automatically extracting context from the command-line interpreter, and combining it with a large language model for error detection, the problem of low efficiency in command error detection is solved, realizing automated and intelligent error detection and improving the work efficiency of engineers.

CN122489406APending Publication Date: 2026-07-31SHENZHEN QINGCHENG JIZHI TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHENZHEN QINGCHENG JIZHI TECHNOLOGY CO LTD
Filing Date
2026-04-27
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

In existing technologies, when errors occur during command-line interpreter execution, engineers need to manually copy the error messages for analysis, resulting in low detection efficiency and impacting work efficiency.

Method used

By using detection functions in the command-line interpreter to obtain execution status information, automatically extracting the associated context, and using a large language model for error detection, error detection commands are generated, thus achieving automated error detection.

Benefits of technology

It simplifies the error troubleshooting process, improves the efficiency and accuracy of command error detection, and significantly enhances the work efficiency of engineers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122489406A_ABST
    Figure CN122489406A_ABST
Patent Text Reader

Abstract

This application relates to a command error detection method, apparatus, device, storage medium, and program product. The method includes: after the execution of a received input command by a command-line interpreter has ended, and before a prompt for further input is displayed, obtaining execution status information of the input command from the command-line interpreter using a detection function assigned to a command-line prompt variable; if the execution status information indicates that the input command execution failed, extracting the associated context of the input command from a command execution log recorded for the command-line interpreter; generating an error detection command for the input command based on the input command, the associated context, and the execution status information; and invoking a large language model to perform error detection based on the error detection command, obtaining the command error detection result for the input command. This method can improve the efficiency of command error detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a command error detection method, apparatus, device, storage medium, and program product. Background Technology

[0002] With the development of computer technology, the demand for software program development continues to grow. Engineers usually interact directly with the operating system through a command-line interpreter. Engineers input commands through the command-line interpreter, which then interacts with the operating system to complete the command execution.

[0003] In related technologies, when a command-line interpreter encounters an error while executing a command, engineers typically rely on the error message to subjectively determine the error content, manually copy the erroneous command content, and use a search engine to analyze the cause. This process is cumbersome, resulting in low efficiency in command error detection and severely impacting the engineers' work efficiency. Summary of the Invention

[0004] Therefore, it is necessary to provide a command error detection method, apparatus, device, storage medium, and program product that can improve the efficiency of command error detection in response to the above-mentioned technical problems.

[0005] Firstly, this application provides a command error detection method, including:

[0006] Before the execution of the received input command by the command line interpreter ends and before the prompt for input is displayed, the execution status information of the input command is obtained from the command line interpreter through the detection function assigned in the command line prompt variable;

[0007] If it is determined that the input command failed to execute based on the execution status information, the associated context of the input command is extracted from the command execution log recorded for the command line interpreter.

[0008] Based on the input command, the associated context, and the execution status information, an error detection command is generated for the input command;

[0009] The large language model is invoked, and error detection is performed based on the error detection command through the large language model to obtain the command error detection result of the input command.

[0010] Secondly, this application also provides a command error detection device, comprising:

[0011] The acquisition module is used to acquire the execution status information of the input command from the command line interpreter through a detection function assigned in the command line prompt variable after the execution of the received input command by the command line interpreter has ended and before the prompt for input is displayed;

[0012] An extraction module is used to extract the associated context of the input command from the command execution log recorded for the command line interpreter when it is determined that the input command has failed to execute based on the execution status information.

[0013] The request module is used to generate an error detection command for the input command based on the input command, the associated context, and the execution status information;

[0014] The execution module is used to call the large language model, perform error detection based on the error detection command through the large language model, and obtain the command error detection result of the input command.

[0015] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described method.

[0016] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.

[0017] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described method.

[0018] The aforementioned command error detection method, device, equipment, storage medium, and program product automatically obtain execution status information using a detection function assigned in the command prompt variable after the input command execution ends and before the prompt is displayed, achieving automatic perception of command execution results without manual intervention. When command execution fails, it can automatically extract the associated context from the recorded command execution log and generate an error detection command by combining the input command and execution status information. On the one hand, the associated context can provide complete data support for subsequent command error detection; on the other hand, it avoids the tedious operation of manually copying error information. Finally, it completes automated error detection based on the error detection command by calling a large language model. The entire process realizes automated perception of command errors, intelligent extraction of context, and intelligent analysis, greatly simplifying the error troubleshooting process, effectively improving the efficiency and accuracy of command error detection, and significantly improving the efficiency of engineers developing based on the command line interpreter. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a diagram illustrating the application environment of a command error detection method in one embodiment;

[0021] Figure 2 This is a flowchart illustrating a command error detection method in one embodiment;

[0022] Figure 3 This is a flowchart illustrating step 204 in one embodiment;

[0023] Figure 4 This is a schematic diagram of the system architecture of a command error detection system in one embodiment;

[0024] Figure 5 This is a schematic diagram of the application process of a command error detection system in one embodiment;

[0025] Figure 6 This is a structural block diagram of a command error detection device in one embodiment;

[0026] Figure 7 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0027] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0028] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.

[0029] The command error detection method provided in this application embodiment can be applied to, for example, Figure 1The application environment shown is as follows. Terminal 101 communicates with server 102 via a network. A data storage system can store the data that server 102 needs to process. The data storage system can be integrated onto server 102, or it can be located in the cloud or on another network server. Terminal 101 can be equipped with a command-line interpreter, and server 102 can deploy a large language model.

[0030] The user inputs commands to the command-line interpreter through the input device of terminal 101. The command-line interpreter receives and executes the input commands. Before the execution of the received input commands by the command-line interpreter ends and before the prompt for input is displayed, the execution status information of the input commands is obtained from the command-line interpreter through the detection function assigned in the command-line prompt variable. If it is determined that the input command has failed to execute based on the execution status information, the associated context of the input command is extracted from the command execution log recorded for the command-line interpreter. Based on the input command, associated context, and execution status information, an error detection command is generated for the input command. The large language model deployed on server 102 is called to perform error detection based on the error detection command, and the command error detection result of the input command is obtained. Then, server 102 returns the command error detection result to terminal 101 for display.

[0031] The terminal 101 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, etc. The server 102 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.

[0032] In one exemplary embodiment, such as Figure 2 As shown, a command error detection method is provided, which can be applied to... Figure 1 Taking the terminal in the example, the explanation includes the following steps 201 to 204. Wherein:

[0033] Step 201: After the execution of the received input command by the command line interpreter has ended and before the prompt for input is displayed, obtain the execution status information of the input command from the command line interpreter through the detection function assigned in the command line prompt variable.

[0034] The command line interpreter (CLE) is a text-based command interface that allows users to interact directly with the operating system. It belongs to the interpreter category of software programs. Specifically, the CLE receives commands input by the user, calls the operating system to execute the commands, and returns the execution results to the user.

[0035] For example, commonly used command-line interpreters include Bash on Linux systems, PowerShell on Windows systems, and Cmd.

[0036] The command prompt variable is a built-in variable of the command-line interpreter. It is used to automatically execute a piece of code before the prompt is displayed after each command execution. For example, in Bash, the built-in command prompt variable is "PROMPT_COMMAND".

[0037] The prompt is a character displayed by the command-line interpreter after the previous command has been executed, prompting the user to enter the next command.

[0038] A detection function is a function used to obtain the execution status information of the previous input command. For example, a hook function can be used as a detection function to automatically obtain the execution status information after the command line interpreter has finished executing the input command and obtained the corresponding execution status information.

[0039] In some embodiments, the detection function is assigned a value to a command prompt variable, that is, the detection function is associated with a command prompt-related variable, thereby binding the detection function with the command prompt. This allows the detection function to be executed after each command execution and before the prompt is displayed, and the execution status information of the input command can be obtained through the detection function.

[0040] For example, still using the Bash command-line interpreter, the following pseudocode can be used to implement a function to detect variable assignment at the command-line prompt:

[0041] PROMPT_COMMAND="command_failed_hook;$PROMPT_COMMAND".

[0042] Here, "PROMPT_COMMAND" is a predefined command prompt variable in the Bash command-line interpreter; "=" is the assignment operator; "command_failed_hook" is a hook function used to detect command execution failure status; and "$PROMPT_COMMAND" is a variable reference that retains and appends the original value of the variable, that is, it retains the function of "preparing to display the prompt after each command execution".

[0043] In some embodiments, the execution status of an input command can be in progress, execution failed, or execution successful. The execution status information of an input command refers to information that can be used to determine whether the input command has been executed successfully. For example, the execution status information can be one or more of the following: the execution duration of the input command, key fields in the execution result, and exit code, as long as it can reflect the execution status of the input command.

[0044] Step 202: If it is determined that the input command failed to execute based on the execution status information, extract the associated context of the input command from the command execution log recorded for the command line interpreter.

[0045] For example, in some embodiments, if the exit code is non-zero when the execution status information is an exit code, it means that the input command failed to execute; if the execution duration exceeds a preset duration threshold when the execution status information is an execution duration, it means that the input command failed to execute.

[0046] Among them, the command execution log recorded for the command-line interpreter is obtained by continuously collecting and recording the input, output, execution results and other operation-related data of the command-line interpreter in chronological order during the startup and running of the command-line interpreter.

[0047] In some embodiments, command execution log recording can be automatically triggered by a preset logging command; for example, log recording can be started via a script; furthermore, the script can be injected into the configuration file of the command-line interpreter, so that the command-line interpreter will automatically run the script injected in the configuration file every time it loads the configuration file; at the same time, since the command-line interpreter may load the configuration file multiple times during operation, in order to avoid recursive calls and log exceptions caused by repeated startup of the log recording script, the environment status of the command-line interpreter can be checked before running the script, that is, to determine whether a running log recording script process already exists in the current environment. If it exists, the script will not be run repeatedly; if it does not exist, the script will be run.

[0048] In some embodiments, the associated context of an input command refers to historical data associated with the input command, such as the previous input command, the output of the previous input command, historical error information, and the current environmental state.

[0049] In some embodiments, the associated context of an input command can be the K log entries closest to the input command in the command execution log; or it can be the K historical input commands closest to the current input command in the command execution log, where K is a positive integer.

[0050] Understandably, the context associated with input commands can provide comprehensive data support for subsequent error analysis, thereby improving the effectiveness of error analysis.

[0051] Step 203: Based on the input command, associated context, and execution status information, generate an error detection command for the input command.

[0052] In some embodiments, the input command, associated context, and execution status information can be logically concatenated, and an error detection command for the input command can be generated according to a preset command parsing rule.

[0053] In other embodiments, the command generation model may generate the command based on the input command, the associated context, and the execution status information to obtain the error detection command for the input command.

[0054] Step 204: Call the large language model to perform error detection based on the error detection command, and obtain the command error detection result of the input command.

[0055] In some embodiments, the Large Language Model (LLM) can be GPT, Claude, Qwen, etc.

[0056] In some embodiments, the large language model can be deployed on a server, and the command-line interpreter running on the terminal can call the large language model through an API (Application Programming Interface) to perform error detection based on the error detection command and obtain the command error detection result of the input command.

[0057] In some embodiments, after receiving the command error detection result, the terminal can also display it to the user through a confirmation window; furthermore, the confirmation window can also display feedback controls, such as accept and reject controls, so that the user can evaluate the error detection result through the feedback controls and thus determine whether to perform subsequent processing, such as in-depth analysis or end analysis.

[0058] In the aforementioned command error detection method, the execution status information is automatically obtained by utilizing the detection function assigned in the command prompt variable after the input command is executed and before the prompt is displayed. This achieves automatic perception of the command execution result without manual intervention. When command execution is determined to have failed, the associated context can be automatically extracted from the recorded command execution log. Combined with the input command and execution status information, an error detection command is generated. On the one hand, the associated context can provide complete data support for subsequent command error detection; on the other hand, the tedious operation of manually copying error information is avoided. Finally, the large language model is called to complete automated error detection based on the error detection command. The entire process realizes automated perception of command errors, intelligent extraction of context, and intelligent analysis, greatly simplifying the error troubleshooting process, effectively improving the efficiency and accuracy of command error detection, and significantly enhancing the efficiency of engineers developing based on the command-line interpreter.

[0059] In one exemplary embodiment, such as Figure 3 As shown, step 204 includes steps 301 to 302. Wherein:

[0060] Step 301: Generate detection and analysis prompts based on error detection commands and preset prompt templates.

[0061] Among them, the preset prompt template is used to standardize the generation format of the prompts, thereby generating standardized detection and analysis prompts; the preset prompt template predefines the combination methods of various prompt elements.

[0062] In some embodiments, there may be multiple preset prompt templates. Based on these, multiple detection and analysis prompts can be generated according to the error detection command based on the multiple preset prompt templates. Then, the multiple detection and analysis prompts can be semantically scored using a large language model, and error detection can be performed based on the detection and analysis prompt with the highest score to obtain the command error detection result of the input command. The detection and analysis prompt with the highest score is also the prompt that best matches the error detection command.

[0063] In other embodiments, there may be multiple preset prompt templates. Based on this, a target preset prompt template can be determined from the multiple preset prompt templates according to the feature information contained in the error detection command. Then, a detection analysis prompt with a higher matching degree can be generated based on the target preset prompt template and the error detection command, so as to improve the targeting and detection accuracy of the large language model when performing error analysis. For example, there are two preset prompt templates. If the input command contained in the error detection command contains a preset target character, the first preset prompt template is determined as the target preset prompt template. If the input command contained in the error detection command does not contain a preset target character, the second preset prompt template is determined as the target preset prompt template.

[0064] In some embodiments, the preset prompt template can also be pre-configured in the large language model. In this way, the command line interpreter can directly call the large language model based on the error detection command. The large language model generates a detection and analysis prompt based on the error detection command and the preset prompt template, and then performs error analysis based on the detection and analysis prompt to obtain the command error detection result of the input command.

[0065] Step 302: Call the large language model, which performs error analysis based on the detection and analysis prompts to obtain the command error detection results of the input command.

[0066] For example, a preset prompt template could be: "Please analyze the reason why the execution status information 'C' of the input command 'A' appears, taking into account the associated context 'B' of the input command 'A'." Here, A requires the specific content of the input command, B requires the specific content of the associated context, and C requires the specific content of the execution status information. Combining the input command, associated context, and execution status information contained in the error detection command yields a complete detection and analysis prompt. This prompt is then input into a large language model, which outputs the command error detection result for the input command.

[0067] In the above embodiments, by combining error detection commands with preset prompt templates to generate standardized detection and analysis prompts, and calling a large language model to perform error analysis based on these prompts, on the one hand, the input format and reasoning logic of error detection can be unified, improving the accuracy and consistency of the large language model in parsing command anomalies; on the other hand, the semantic understanding and logical reasoning capabilities of the large language model can be fully utilized to automatically complete the detection of command execution anomalies, improving the efficiency and accuracy of error detection.

[0068] In one exemplary embodiment, the command error detection method further includes:

[0069] The environment status of the command-line interpreter is detected, and the environment status detection results of the command-line interpreter are obtained.

[0070] Among them, environment status detection refers to detecting the current running environment of the command line interpreter to determine whether the log recording function is in effect.

[0071] In some embodiments, the environment status detection result may include at least one of the following: the logging command was not executed, the logging command was executed, the logging process does not exist, or the logging process is running.

[0072] In some embodiments, the aforementioned environment state detection may be performed before the command-line interpreter receives each input command, or before each configuration file is loaded, thereby ensuring that the log-recording command is executed in a timely manner, and thus ensuring that the recorded command execution log can cover the complete data of the command-line interpreter.

[0073] If the environment status detection result indicates that the logging command has not been executed, the logging command is executed to obtain the command execution log recorded for the command line interpreter; the logging command is used to instruct the command line interpreter to be recorded.

[0074] If the environment status detection result indicates that the log recording command has not been executed, it means that the recording process is not currently started. Therefore, it is necessary to start recording the command line interpreter by executing the log recording command.

[0075] If the environment status detection result indicates that the logging command has been executed, it means that the recording process has already started. Therefore, there is no need to repeatedly execute the logging command, which effectively reduces the possibility of log errors caused by recursion.

[0076] In some embodiments, the environment status of the command-line interpreter can be periodically checked, so that if the logging command is not executed or is executed abnormally, the logging command can be executed in a timely manner, thereby starting the logging process.

[0077] In the above embodiments, by performing environment status detection on the command line interpreter before starting the logging command, it is possible to accurately determine whether a logging process is already running in the current environment. The logging operation is only started when the logging command is not executed, thereby effectively avoiding the recursive call problem caused by repeated execution of the logging command and ensuring that the logging process is stable and reliable.

[0078] In an exemplary embodiment, if it is determined that the input command failed to execute based on the execution status information, the associated context of the input command is extracted from the command execution log recorded for the command line interpreter, including:

[0079] If the execution of an input command fails based on the execution status information, determine the current position of the input command in the command execution log.

[0080] In some embodiments, the failed input command can be used as a matching keyword to parse and match the command execution log line by line, and log records that are completely consistent with or semantically match the input command can be retrieved in the command execution log; the line number, timestamp, or log offset of the retrieved log record is determined as the current position of the input command in the command execution log.

[0081] In other embodiments, the command execution log can assign a log identifier to each recorded log entry, so that the log identifier corresponding to the input command can be used as the current position of the input command in the command execution log.

[0082] Extract the k log entries preceding the current position from the command execution log to obtain the associated context of the input command; k is a positive integer.

[0083] For example, k can be 1, meaning the previous log entry before the current position is used as the associated context for the input command.

[0084] In some embodiments, considering that the input command may not be the latest log in the command execution log, multiple logs before the current position and multiple logs after the current position can be extracted from the command execution log to obtain the associated context of the input command.

[0085] In some embodiments, after extracting k logs prior to the current position from the command execution log to obtain the associated context of the input command, the associated context can be further divided into multiple levels based on the distance of each log in the associated context relative to the current position; different levels correspond to different distance ranges. For example, the associated context within a first distance range is determined as the associated context of the first level, and the associated context within a second distance range is determined as the associated context of the second level, wherein the second distance range is different from the first distance range; furthermore, the second distance range may include the first distance range.

[0086] For example, the ten logs before the current position are extracted as the associated context. The first distance range is from zero to five, that is, the five logs closest to the current position in the associated context are used as the first level of associated context. The second distance range is from zero to ten, that is, the entire associated context is used as the second level of associated context. Obviously, the first level of associated context has less data, but all of them are highly associated contexts. The second level of associated context has more data, but it contains both highly associated contexts and contexts with low correlation.

[0087] Based on this, a first-level error detection command can be generated using the first-level context. The large language model then performs error detection based on this command, yielding the first error detection result for the input command. Feedback on this first error detection result is then received. If the feedback indicates a significant deviation, a second-level error detection command is generated using the second-level context. The large language model then performs error detection again based on this second command, yielding the second error detection result for the input command. If the feedback from the second error detection result still indicates a significant deviation, an alarm is generated to prompt manual intervention. Conversely, if the feedback from the first error detection result indicates a relatively accurate result, no further detection is necessary, and the first error detection result is used as the final error detection result. This multi-level context allows for step-by-step detection, prioritizing the use of a small number of highly relevant contexts for rapid error analysis, and expanding the context range only when detection is insufficient. This effectively reduces model computational overhead and achieves a balance between detection efficiency and accuracy.

[0088] In the above embodiments, by locating the current position of the input command in the command execution log and extracting a preset number of historical logs before that position as the associated context, it is possible to accurately obtain historical operations, environmental changes and prior execution information directly related to the execution of this command. While ensuring the integrity of the context, it avoids introducing irrelevant log data to cause interference, and provides comprehensive data support for subsequent error detection.

[0089] In some embodiments, the execution status information of the input command is obtained from the command line interpreter through a detection function assigned in the command line prompt variable, including:

[0090] Perform string matching on the input command to obtain the string matching result of the input command.

[0091] In some embodiments, a target character library is pre-configured, which contains characteristic strings of non-external input commands, such as typical prefixes and keywords. The input command is matched one by one with the strings in the target character library to obtain the string matching result of the input command.

[0092] In some embodiments, the target character library may also be a feature string containing external input commands, such as typical prefixes and keywords. The input commands are matched one by one with the strings in the target character library to obtain the string matching results of the input commands.

[0093] If the string matching result of the input command indicates that the input command belongs to an external input command, the execution status information of the input command can be obtained from the command line interpreter through the detection function assigned in the command line prompt variable.

[0094] External input commands are distinguished from internal commands; external input commands refer to user commands received and executed by the command line interpreter; internal commands refer to commands that the command line interpreter automatically invokes, generates internally, or generates by the detection logic itself during operation.

[0095] It should be noted that since internal commands are generated or called by the command line interpreter itself, if the error detection process is also triggered for this type of internal command, the detection logic may be recursively triggered by itself, which may cause the command line interpreter to malfunction.

[0096] In the above embodiments, by performing string matching on the input commands, the detection function is triggered only for commands that belong to external input to obtain execution status information. This can effectively prevent the detection function itself or the internal system call commands of the command line interpreter from being mistakenly identified as user input commands and repeatedly triggering the detection logic, thus preventing recursive calls and loop detection, ensuring the stable operation of the command line interpreter, and ensuring the accurate collection of execution status information.

[0097] In some embodiments, the execution status information includes at least one of the following: execution exit code, standard output file information, execution signal information, and execution time information.

[0098] The execution exit code is the status code returned by the command line interpreter after the command is executed, used to indicate whether the command execution was successful or failed; for example, if the execution exit code is zero, it means that the execution was successful; if the execution status code is non-zero, it means that the execution failed.

[0099] The standard output file contains the standard error output generated during command execution. If the standard error output contains a preset keyword used to indicate error output, it means that the execution failed; otherwise, it means that the execution succeeded.

[0100] Execution signals are process control signals sent by the system during the execution of input commands. Execution signal information is used to indicate whether there is an interruption or exception in the execution process. If there is an interruption or exception, it means that the execution has failed; otherwise, it means that the execution has succeeded.

[0101] The execution time information is used to indicate the execution time of the input command. If the execution time exceeds the preset time threshold, it means that the execution has failed; otherwise, it means that the execution has succeeded.

[0102] In some embodiments, when the execution status information includes at least two of the following: execution exit code, standard output file information, execution signal information, and execution time information, the input command execution failure can be determined only when at least two types of information indicate execution failure, thereby reducing the possibility of misjudgment.

[0103] In the above embodiments, by using at least one of the execution exit code, standard output file information, execution signal information and execution time information as execution status information, the actual execution result of the input command can be reflected from multiple dimensions, providing a reliable basis for judging whether the command has failed to execute, and effectively reducing the possibility of misjudgment caused by a single status indicator.

[0104] The following description will be based on specific application examples. Please refer to [link / reference]. Figure 4 , Figure 4 A schematic diagram of the system architecture of the command error detection system according to an embodiment of this application is shown, and its application flow is as follows:

[0105] Users first inject configuration into the command-line interpreter so that it can perform functions such as detection, logging, context extraction, and model invocation.

[0106] For example, regarding the log recording function, taking the Bash command-line interpreter as an example, a log recording script "script -a output.txt" is written into the Bash command-line interpreter's configuration file "~ / .bashrc". This allows the log recording function to be started when the command-line interpreter reads the configuration file. The pseudocode of the log recording script "script -aoutput.txt" is as follows:

[0107] if [[ -z "$SCRIPT_LOGGING" ]]; then

[0108] export SCRIPT_LOGGING=1

[0109] script -q --flush -a ~ / output.txt

[0110] exit

[0111] fi

[0112] Here, `-z "$SCRIPT_LOGGING"` checks if the variable `SCRIPT_LOGGING` is empty; `exportSCRIPT_LOGGING=1` sets the variable `SCRIPT_LOGGING` to 1; `script -q --flush -a ~ / output.txt` writes the contents of the command-line interpreter directly to the save path `~ / output.txt` without overwriting, without displaying unnecessary prompts; `exit` exits the script; and `fi` terminates the IF statement.

[0113] By injecting the above pseudocode into the command-line interpreter's configuration file, when the command-line interpreter reads the configuration file, it will first check whether "SCRIPT_LOGGING" is empty. If it is empty, it will be set to 1, which means that logging is enabled and the contents of the command-line interpreter will be written to the log file in real time to obtain the command execution log. If it is not empty, it means that logging is already enabled, and the execution script will be skipped to prevent recursion.

[0114] Additionally, for the detection function, the PROMPT_COMMAND variable built into the command-line interpreter can be configured using the following pseudocode:

[0115] PROMPT_COMMAND="command_failed_hook; $PROMPT_COMMAND".

[0116] Here, "PROMPT_COMMAND" is a predefined command prompt variable in the Bash command-line interpreter; "=" is the assignment operator; "command_failed_hook" is a hook function used to detect command execution failure status; "$PROMPT_COMMAND" is a variable reference that retains and appends the original value of the variable, that is, it retains the function of "preparing to display the prompt after each command execution"; the hook function is set to read the "$?" variable, which is used to store the execution result of the previous command, such as the execution exit code.

[0117] In this way, the command-line interpreter can execute the hook function before displaying the prompt after each input command is executed. The hook function reads the variable "$?". If the exit code in the variable "$?" is zero, it means that the command was executed successfully and no subsequent process is triggered; if the exit code in the variable "$?" is not zero, it means that the command was executed unsuccessfully and the subsequent detection process is triggered.

[0118] The context extraction function can be implemented using the following pseudocode:

[0119] last_line=$(tail -n 1 ~ / output.txt).

[0120] Here, "~ / output.txt" is the storage path for the command execution log, "last_line" is the variable name, and "tail -n 1" represents viewing the last line of the file; that is to say, the above pseudocode can read the last line of the command execution log; of course, by changing "n 1", it is possible to read the last multiple lines of the command execution log and obtain the associated context of the input command.

[0121] The model invocation function can be implemented through the API interface.

[0122] After completing the above configuration, the user enters a command into the command-line interpreter. The command-line interpreter executes the command, that is, it calls the terminal's operating system to execute the command and captures the terminal's output at the same time. On the other hand, after the command execution is completed, the exit code extraction module extracts the execution exit code from the terminal's output to perform failure detection. In addition, the terminal's output and the extracted execution exit code are also stored synchronously in the server so that the large language model in the server can call the data.

[0123] During the above process, the command line interpreter records in real time through the terminal logging module to obtain the command execution log.

[0124] When the proposed exit code indicates that the input command has failed to execute, the context extraction module extracts the associated context from the command execution log recorded by the terminal log recording module, and calls the large language model deployed on the server through the large language model interface. The large language model generates system prompt words based on the preset prompt template, the extracted associated context, and the stored execution status information, and then performs command error detection based on the system prompt words to obtain the command error detection result.

[0125] During command execution, this module will simultaneously perform running status and failure determination, and hand over the terminal running output to the terminal output capture module. The output data will be synchronously stored in the remote server. At the same time, the command execution exit status will be handed over to the exit code extraction module, which can also pull terminal output logs from the server for supplementary verification.

[0126] Meanwhile, the terminal log recording module will retain operation logs throughout the process, storing the logs in the historical log records for retrospective retention; the generated prompt words will also be updated and archived in the historical log records, forming a complete closed-loop process.

[0127] Please continue reading. Figure 5 , Figure 5 The above-mentioned command error detection system is illustrated in the application flow diagram, including steps S1 to S8, wherein:

[0128] S1, User enters command.

[0129] S2, command execution permission and validity verification. Specifically, if the command has the necessary execution permissions and the verification is valid, the operating system in the terminal is invoked to execute the command, and the terminal output is obtained.

[0130] S3, check if the exit status code is 0. If it is 0, it means the command was executed successfully and the process ends; if it is not 0, it means the command failed and proceed to step S4.

[0131] S4 reads the terminal log file.

[0132] S5, extract the associated context.

[0133] S6, Constructing a model request. For example, a model request can be constructed using the following pseudocode: `sgpt "command: $last_cmd error code: $exit_code context: $context"`, where `sgpt` represents the model invocation tool, and `"command: $last_cmd error code: $exit_code context: $context"` is the constructed model request, which combines the input command, error code, and context to obtain the model request.

[0134] In some embodiments, since the sgpt tool also triggers exit code checks during execution, to avoid recursion, the environment can be checked using the following pseudocode: "if [[ "$last_cmd" != sgpt* ]]; then exit code check". That is, the exit code check is only triggered if the latest input command is not a command generated by the sgpt tool.

[0135] S7 calls the large model API.

[0136] S8 outputs the result to the terminal.

[0137] In the above process, a real-time error interception mechanism based on PROMPT_COMMAND is used to automatically capture the complete terminal context through script commands, constructing a non-actively executed AI error analysis architecture. This architecture features automatic triggering, zero human intervention, anti-recursive triggering, and structured output based on fixed system prompt templates. Because the system does not actively execute commands, actively scan the system, or perform multiple rounds of interaction, it can significantly improve response speed, reduce system resource consumption, reduce additional user operations, and improve context integrity and error analysis accuracy.

[0138] In some embodiments, the above process can also be applied to other command-line interpreters, such as Z shell, Fish (Friendly Interactive Shell), and PowerShell environments; meanwhile, log recording can also be achieved through other means, such as pseudo-terminal agents, system call interception, etc.; meanwhile, the large language model can be deployed locally to provide local model calls, or it can be deployed through edge devices or private model deployment.

[0139] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.

[0140] Based on the same inventive concept, this application also provides a command error detection device for implementing the command error detection method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more command error detection device embodiments provided below can be found in the limitations of the command error detection method described above, and will not be repeated here.

[0141] In one exemplary embodiment, such as Figure 6 As shown, Figure 6 A schematic diagram of a command error detection device is provided. The command error detection device 500 includes:

[0142] The acquisition module 501 is used to acquire the execution status information of the input command from the command line interpreter through a detection function assigned in the command line prompt variable after the execution of the received input command by the command line interpreter has ended and before the prompt for input is displayed.

[0143] Extraction module 502 is used to extract the associated context of the input command from the command execution log recorded for the command line interpreter when it is determined that the input command has failed to execute based on the execution status information.

[0144] The request module 503 is used to generate an error detection command for the input command based on the input command, the associated context, and the execution status information.

[0145] The execution module 504 is used to call the large language model, and to perform error detection based on the error detection command through the large language model to obtain the command error detection result of the input command.

[0146] In some embodiments, the execution module 504 is used to generate a detection analysis prompt based on the error detection command and a preset prompt template; call a large language model, which performs error analysis based on the detection analysis prompt to obtain the command error detection result of the input command.

[0147] In some embodiments, the command error detection device 500 further includes a status detection module, which is used to perform environment status detection on the command line interpreter and obtain the environment status detection result of the command line interpreter; if the environment status detection result indicates that the logging command has not been executed, the logging command is executed to obtain the command execution log recorded for the command line interpreter; wherein, the logging command is used to instruct the command line interpreter to be recorded.

[0148] In some embodiments, the extraction module 502 is used to determine the current position of the input command in the command execution log when it is determined that the input command has failed to execute based on the execution status information; extract k log entries before the current position from the command execution log to obtain the associated context of the input command; k is a positive integer.

[0149] In some embodiments, the acquisition module 510 is used to perform string matching on the input command to obtain the string matching result of the input command; when the string matching result of the input command indicates that the input command belongs to an external input command, the execution status information of the input command is obtained from the command line interpreter through the detection function assigned in the command line prompt variable.

[0150] In some embodiments, the execution status information includes at least one of the following: execution exit code, standard output file information, execution signal information, and execution time information.

[0151] The modules in the aforementioned command error detection device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0152] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a command error detection method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.

[0153] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0154] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described above.

[0155] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.

[0156] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the method described above.

[0157] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.

[0158] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0159] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0160] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A command error detection method characterized by, The method includes: Before the execution of the received input command by the command line interpreter ends and before the prompt for input is displayed, the execution status information of the input command is obtained from the command line interpreter through the detection function assigned in the command line prompt variable; If it is determined that the input command failed to execute based on the execution status information, the associated context of the input command is extracted from the command execution log recorded for the command line interpreter. Based on the input command, the associated context, and the execution status information, an error detection command is generated for the input command; The large language model is invoked, and error detection is performed based on the error detection command through the large language model to obtain the command error detection result of the input command.

2. The method of claim 1, wherein, The process of calling the large language model, performing error detection based on the error detection command using the large language model, and obtaining the command error detection result of the input command includes: Based on the error detection command and the preset prompt template, a detection and analysis prompt message is generated; The large language model is invoked, and the large language model performs error analysis based on the detection and analysis prompt to obtain the command error detection result of the input command.

3. The method of claim 1, wherein, The method further includes: An environment state detection is performed on the command-line interpreter to obtain the environment state detection result of the command-line interpreter. If the environment status detection result indicates that the logging command has not been executed, the logging command is executed to obtain a command execution log recorded for the command line interpreter; wherein, the logging command is used to instruct the command line interpreter to be recorded.

4. The method of claim 1, wherein, When it is determined that the input command failed to execute based on the execution status information, the associated context of the input command is extracted from the command execution log recorded for the command line interpreter, including: If it is determined that the input command failed to execute based on the execution status information, the current position of the input command in the command execution log is determined; Extract the k log entries preceding the current position from the command execution log to obtain the associated context of the input command; k is a positive integer.

5. The method of claim 1, wherein, The step of obtaining the execution status information of the input command from the command line interpreter through the detection function assigned in the command line prompt variable includes: Perform string matching on the input command to obtain the string matching result of the input command; If the string matching result of the input command indicates that the input command belongs to an external input command, the execution status information of the input command is obtained from the command line interpreter through the detection function assigned in the command line prompt variable.

6. The method according to any one of claims 1-5, characterized in that, The execution status information includes at least one of the following: execution exit code, standard output file information, execution signal information, and execution time information.

7. A command error detection apparatus characterized by comprising: The device includes: The acquisition module is used to acquire the execution status information of the input command from the command line interpreter through a detection function assigned in the command line prompt variable after the execution of the received input command by the command line interpreter has ended and before the prompt for input is displayed; An extraction module is used to extract the associated context of the input command from the command execution log recorded for the command line interpreter when it is determined that the input command has failed to execute based on the execution status information. The request module is used to generate an error detection command for the input command based on the input command, the associated context, and the execution status information; The execution module is used to call the large language model, perform error detection based on the error detection command through the large language model, and obtain the command error detection result of the input command.

8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.