Command execution method and device, computer equipment and storage medium
By implementing command execution methods between Java and Python, obtaining and processing the parameters and execution results of external commands, the cumbersome interoperability between the two languages is solved, and the efficiency and flexibility of system control and resource management are improved.
Patent Information
- Application Number
- CN202411493221.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-02-14
AI Technical Summary
The interoperability between Java and Python is relatively cumbersome, which is not conducive to system control and resource management.
By obtaining command parameters of external commands based on the second language, calling the command execution class instance of the first language, executing external commands of the second language, and reading data asynchronously using the data stream processing class of the first language during the execution process, to get the execution result of external commands.
Reduces the cumbersome degree of interoperability between the first and second languages, improves the efficiency of inter-process communication and error handling, improves the flexibility of process processing, and realizes real-time acquisition of data generated during execution, avoiding Program blockage caused by synchronous waiting for output.
Smart Images

Figure CN119440724A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of cross-language programming, and in particular to a command execution method, apparatus, computer device and storage medium. Background Art
[0002] Java (a programming language) and Python (a programming language) are two widely used programming languages, each with unique advantages in different application fields. Java, with its strong typing, object-oriented and cross-platform features, occupies an important position in enterprise applications, Android system development and other fields. Python, with its concise syntax, rich libraries and powerful data processing capabilities, is widely popular in scientific computing, artificial intelligence, script automation and other fields.
[0003] However, in the field of software engineering, interoperability between different programming languages has always been an important issue. In the existing technology, the interoperability between Java and Python is relatively cumbersome, which is not conducive to system control and resource management. Summary of the invention
[0004] Based on this, it is necessary to provide a command execution method, apparatus, computer device and storage medium that can reduce the complexity of system control and resource management in order to address the above technical problems.
[0005] In a first aspect, the present application provides a command execution method. The method comprises:
[0006] Acquire command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter transferred to the external command;
[0007] According to the command parameters, calling the command execution class instance of the first language to execute the external command of the second language;
[0008] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0009] In one of the embodiments, the command execution class instance is a local command executor implementing a LocalCommandExecutorImpl class instance;
[0010] The step of calling the command execution class instance of the first language according to the command parameter to execute the external command of the second language includes:
[0011] Based on the command parameters, the runProcess auxiliary method inside the executeCommand method of the execution command is called according to the LocalCommandExecutorImpl class instance to execute the external command of the second language.
[0012] In one embodiment, based on the command parameters, calling the runProcess auxiliary method in the executeCommand method according to the LocalCommandExecutorImpl class instance to execute the external command in the second language includes:
[0013] Determine the timeout period based on the execution time of historical commands;
[0014] Based on the command parameters and the timeout period, the runProcess auxiliary method in the executeCommand method is called according to the LocalCommandExecutorImpl class instance to execute the external command in the second language.
[0015] In one embodiment, during the execution of the external command, calling the data stream processing class of the first language and asynchronously reading the data generated during the execution to obtain the execution result of the external command includes:
[0016] During the execution of the external command, calling the data stream processing class of the first language to asynchronously read the data generated during the execution;
[0017] The result processing class of the first language is called to encapsulate the read data to obtain the execution result of the external command.
[0018] In one embodiment, the method further comprises:
[0019] The abnormal information generated during the execution of the external command is recorded in a log.
[0020] In one embodiment, the method further comprises:
[0021] When the external command is executed, the processing process corresponding to the external command is destroyed.
[0022] In a second aspect, the present application also provides a command execution device. The device comprises:
[0023] An acquisition module, used for acquiring command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter passed to the external command;
[0024] A first calling module, used to call the command execution class instance of the first language according to the command parameters to execute the external command of the second language;
[0025] The second calling module is used to call the data flow processing class of the first language during the execution of the external command, and asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0026] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0027] Acquire command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter transferred to the external command;
[0028] According to the command parameters, calling the command execution class instance of the first language to execute the external command of the second language;
[0029] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0030] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0031] Acquire command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter transferred to the external command;
[0032] According to the command parameters, calling the command execution class instance of the first language to execute the external command of the second language;
[0033] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0034] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0035] Acquire command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter transferred to the external command;
[0036] According to the command parameters, calling the command execution class instance of the first language to execute the external command of the second language;
[0037] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0038] The above-mentioned command execution method, device, computer equipment and storage medium obtain the command parameters of the external command based on the second language to call the command execution class instance of the first language according to the command parameters, execute the external command of the second language, and then call the data flow processing class of the first language to asynchronously read the data generated during the execution process to obtain the execution result of the external command. According to the above content, it can be seen that the present application can realize the seamless calling of the external command of the second language through the first language through the above content, which reduces the cumbersomeness of the interaction between the first language and the second language, including the smooth progress of system control and resource management, and, by seamlessly calling the external command of the second language through the first language, the efficiency of inter-process communication and error handling is improved, and the flexibility of process processing is improved; further, by calling the data flow processing class of the first language to asynchronously read the data generated during the execution process, the data processing efficiency for the external command is improved, and the real-time acquisition of the data generated during the execution process is realized, avoiding the program blocking caused by synchronous waiting for output. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] FIG1 is an application environment diagram of a command execution method provided by an embodiment of the present application;
[0040] FIG2 is a schematic diagram of a flow chart of a first command execution method provided in an embodiment of the present application;
[0041] FIG3 is a schematic diagram of a flow chart of a second command execution method provided in an embodiment of the present application;
[0042] FIG4 is a schematic diagram of a flow chart of a third command execution method provided in an embodiment of the present application;
[0043] FIG5 is a schematic diagram of a flow chart of a fourth command execution method provided in an embodiment of the present application;
[0044] FIG6 is a structural block diagram of a command execution device provided in an embodiment of the present application;
[0045] FIG. 7 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0047] The command execution method provided in the embodiment of the present application can be applied in the application environment shown in Figure 1. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. By obtaining the command parameters of the external command based on the second language, the command execution class instance of the first language is called according to the command parameters, and the external command of the second language is executed. Then, the data stream processing class of the first language is called to asynchronously read the data generated during the execution process to obtain the execution result of the external command. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.
[0048] In one embodiment, as shown in FIG. 2 , a command execution method is provided, which is described by taking the method applied to the server 104 in FIG. 1 as an example, and includes the following steps:
[0049] S201: Acquire command parameters of an external command based on a second language.
[0050] The command parameters include the interpreter path, script file name, and parameters passed to the external command.
[0051] It should be noted that in order to ensure that the external commands in the second language can be executed smoothly later, it is necessary to build command parameters in advance to realize the execution of external commands in the second language based on command parameters; specifically, a command array can be defined, which contains the interpreter path (that is, the Python interpreter path), the script file name (that is, the Python script file name) and the parameters passed to the external command (that is, the parameters passed to the Python script); to realize the operation of obtaining the command parameters of the external command based on the second language.
[0052] Specifically, the code representation of obtaining the command parameters of the external command based on the second language is as follows:
[0053] String[]cmd={"python","compare_strings.py", "searchQuery", "searchResult"}.
[0054] S202: Calling a command execution class instance of the first language according to command parameters to execute an external command of the second language.
[0055] It should be noted that, in order to ensure that the external commands in the second language can be executed smoothly, the system can be initialized in advance to create a command execution class instance in the first language, and then execute the external commands in the second language according to the command execution class instance in the first language.
[0056] Specifically, the code representation of creating a command execution class instance of the first language is as follows:
[0057] LocalCommandExecutorImpl executor = new LocalCommandExecutorImpl().
[0058] S203, during the execution of the external command, calling the data stream processing class of the first language, asynchronously reading the data generated during the execution process to obtain the execution result of the external command.
[0059] It should be noted that in order to avoid affecting the execution process of the main thread during the process of obtaining data, the data generated during the execution process can be read asynchronously to avoid program blocking due to synchronous waiting for output.
[0060] Further explanation: in order to ensure that the execution result of the external command can be processed smoothly afterwards, the data generated during the execution process is encapsulated to obtain the execution result of the external command.
[0061] In one embodiment of the present application, the first language may be JAVA and the second language may be Python; in the process of subsequent processing of the execution result of the external command, the JAVA program may use the data in the ExecuteResult object for subsequent processing, wherein the subsequent processing may include analyzing the output result of the Python external command.
[0062] Specifically, the code representation of using the data in the ExecuteResult object for subsequent processing is as follows:
[0063] int exitCode = res.getExitCode();
[0064] String output = res.getExecuteOut();
[0065] String errors = res.getErr();
[0066] In another embodiment of the present application, when processing output streams and error streams, the present application can use a thread synchronization mechanism to ensure data consistency and integrity, thereby optimizing data management in a multi-threaded environment and preventing data competition and inconsistency issues.
[0067] The above-mentioned command execution method obtains the command parameters of the external command based on the second language to call the command execution class instance of the first language according to the command parameters, executes the external command of the second language, and then calls the data flow processing class of the first language to asynchronously read the data generated during the execution process to obtain the execution result of the external command. According to the above content, it can be known that the present application can realize the seamless calling of the external command of the second language through the first language through the above content, which reduces the cumbersomeness of the interaction between the first language and the second language, including the smooth progress of system control and resource management, and, by seamlessly calling the external command of the second language through the first language, the efficiency of inter-process communication and error handling is improved, and the flexibility of process processing is improved; further, by calling the data flow processing class of the first language to asynchronously read the data generated during the execution process, the data processing efficiency for the external command is improved, and the real-time acquisition of the data generated during the execution process is realized, avoiding the program blocking caused by synchronous waiting for output.
[0068] In one embodiment, if the command execution class instance is a LocalCommandExecutorImpl class instance that implements a local command executor, when it is necessary to call the command execution class instance of the first language according to the command parameters to execute an external command of the second language, the following contents may be specifically included:
[0069] Based on the command parameters, the runProcess auxiliary method inside the executeCommand method of the execution command is called according to the LocalCommandExecutorImpl class instance to execute the external command of the second language.
[0070] The program expression of calling the executeCommand method is as follows:
[0071] ExecuteResult res = executor.executeCommand(cmd, 20).
[0072] The runProcess auxiliary method is responsible for starting the second voice process, managing input and output streams, handling timeouts, and capturing execution results. The program corresponding to calling the runProcess auxiliary method is shown below:
[0073] private ExecuteResult runProcess(Process proc, long timeout, booleanprintOut) {
[0074] / / Implementation details...
[0075] }
[0076] In one embodiment of the present application, multiple overloaded versions of the executeCommand method may be provided to support different forms of command input and configuration, thereby improving the flexibility and ease of use of the system, allowing users to choose the most appropriate command execution method according to actual needs.
[0077] Specifically, as shown in FIG3 , based on the command parameters, the runProcess auxiliary method in the executeCommand method of the LocalCommandExecutorImpl class instance is called to execute the external command of the second language, which may include the following contents:
[0078] S301, determining a timeout period according to the execution time of historical commands.
[0079] The historical commands refer to the external commands of the second voice that were successfully executed at historical moments.
[0080] It should be noted that in order to ensure that the timeout period can be effectively used to determine whether there is an execution exception in the external command of the second language, the effective time interval of the external command execution time can be determined based on the execution time of the historical commands, and then the time exceeding the effective time interval is used as the timeout period.
[0081] Specifically, when it is necessary to determine the timeout period based on the execution time of historical commands, the longest execution time and the shortest execution time can be determined from the execution time of historical commands, and the range between the longest execution time and the shortest execution time is used as the effective time interval of the external command execution time, and the time exceeding the longest execution time is used as the timeout period. Furthermore, a time variable can be pre-set, and after determining the effective time interval, the sum of the longest execution time and the time variable is used as the timeout period.
[0082] To further explain, in order to ensure that the determination of the timeout period is universal, in the process of determining the timeout period, it is necessary to select the execution time that appears most frequently from the execution time of historical commands, and then determine the timeout period based on the execution time that appears most frequently.
[0083] In one embodiment of the present application, when it is necessary to determine the timeout period, the execution time that appears most frequently in the execution time of historical commands can be selected, and a time variable can be set in advance. After determining the execution time that appears most frequently, the sum of the execution time that appears most frequently and the time variable is used as the timeout period.
[0084] To further explain, in order to ensure that the determination of the timeout period can refer to the execution time of each historical command, the average execution time can be determined based on the execution time of the historical commands, and then the timeout period can be determined based on the average execution time.
[0085] In one embodiment of the present application, when it is necessary to determine the timeout time, the execution time of the historical commands can be averaged according to the number of historical commands, and the resulting running result is the average execution time. In addition, a time variable is set in advance. After the average execution time is determined, the sum of the average execution time and the time variable is used as the timeout time.
[0086] S302, based on the command parameters and the timeout period, the runProcess auxiliary method in the executeCommand method is called according to the LocalCommandExecutorImpl class instance to execute the external command in the second language.
[0087] In one embodiment of the present application, when it is necessary to execute an external command in a second language, the following steps may be included: (1) System initialization, creating an instance of the LocalCommandExecutorImpl class, which is responsible for executing the external command in the second language; (2) Constructing command parameters based on the external command in the second language, defining the command parameters, which include the interpreter path, script file name, and the parameters passed to the external command. (3) Executing the command, calling the executeCommand method, passing in the command parameters and timeout, and starting to execute the external command in the second language. (4) Command execution and management Calling the runProcess auxiliary method in the executeCommand method to execute the external command in the second language, the runProcess auxiliary method is responsible for starting the second language process, managing input and output streams, handling timeouts, and capturing execution results.
[0088] The above command execution method determines a timeout period to implement, based on command parameters and timeout period, calling the runProcess auxiliary method within the executeCommand method of the execution command according to the LocalCommandExecutorImpl class instance to execute the external command of the second language; by determining the timeout period, timeout control for the external command is implemented to ensure that the external command running for a long time can be terminated in time, thereby enhancing the stability and responsiveness of the system and avoiding the waste of system resources caused by the long execution time of the external command, thereby realizing the seamless call of the external command of the second language through the first language, reducing the cumbersomeness of the interaction between the first language and the second language, including the smooth progress of system control and resource management.
[0089] In one embodiment, as shown in FIG. 4, when it is necessary to call the data stream processing class of the first language during the execution of an external command, asynchronously read the data generated during the execution process to obtain the execution result of the external command, the following contents may be specifically included;
[0090] S401, during the execution of the external command, calling the data stream processing class of the first language to asynchronously read the data generated during the execution.
[0091] In one embodiment of the present application, the data stream processing class of the first language can be a StreamGobbler class. During the execution of an external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution process. The StreamGobbler class can be used to asynchronously read the standard output and error output streams of the external command to achieve asynchronous reading of the data generated during the execution process.
[0092] Specifically, the code for using the StreamGobbler class to asynchronously read the standard output and error output streams of external commands is as follows:
[0093] public class StreamGobbler extends Thread {
[0094] / / Implementation details...
[0095] }
[0096] S402, calling the result processing class of the first language, encapsulating the read data, and obtaining the execution result of the external command.
[0097] In one embodiment of the present application, the result processing class of the first language can be an ExecuteResult class. When the result processing class of the first language is called to encapsulate the read data and obtain the execution result of the external command, the ExecuteResult class can be used to encapsulate the execution result of the external command, including the exit code, output content and error message.
[0098] Specifically, the code that uses the ExecuteResult class to encapsulate the execution result of an external command is as follows:
[0099] public class ExecuteResult {
[0100] / / Implementation details...
[0101] }
[0102] The command execution method asynchronously reads the data generated during the execution process by calling the data stream processing class of the first language; and encapsulates the read data to obtain the execution result of the external command by calling the result processing class of the first language; wherein, the data processing efficiency for the external command is improved by asynchronously reading the data generated during the execution process, and the data generated during the execution process is obtained in real time, avoiding program blocking caused by synchronous waiting for output; and, by encapsulating the data, it is ensured that the execution result can be accessed or processed in a unified form, thereby improving the processing convenience of the execution result in the subsequent processing process.
[0103] In one embodiment, to ensure that the system has detailed error tracking and system monitoring capabilities, the present application may also include the following: logging the exception information generated during the execution of external commands.
[0104] The abnormal information may include but is not limited to: abnormal information and error information.
[0105] In order to further improve the maintainability and monitoring capabilities of the system, key operations generated during the execution of external commands can also be logged.
[0106] The above command execution method logs the exception information generated during the execution of external commands so that the system can capture and record the exception and error information during the execution process, provides detailed error tracking and system monitoring capabilities, and enhances the robustness and maintainability of the system.
[0107] In one embodiment, in order to avoid resource leakage and improve the overall performance and stability of the system, the present application may also include the following content: when the external command is executed, the processing process corresponding to the external command is destroyed.
[0108] The above command execution method destroys the processing process corresponding to the external command when the external command is executed, so as to automatically close the open stream and destroy the process after the command is executed, ensure that resources are released correctly, avoid resource leakage, and improve the overall performance and stability of the system.
[0109] In one embodiment, as shown in FIG5 , when it is necessary to execute a command for an external command, the following contents may be specifically included:
[0110] S501: Acquire command parameters of an external command based on a second language.
[0111] S502: Determine a timeout period according to the execution time of the historical commands.
[0112] S503: Based on the command parameters and the timeout period, the runProcess auxiliary method in the executeCommand method is called according to the LocalCommandExecutorImpl class instance to execute the external command in the second language.
[0113] S504, during the execution of the external command, calling the data stream processing class of the first language to asynchronously read the data generated during the execution.
[0114] S505: Log the abnormal information generated during the execution of the external command.
[0115] S506, calling the result processing class of the first language, encapsulating the read data, and obtaining the execution result of the external command.
[0116] S507: When the external command is executed, destroy the processing process corresponding to the external command.
[0117] The above-mentioned command execution method obtains the command parameters of the external command based on the second language to call the command execution class instance of the first language according to the command parameters, executes the external command of the second language, and then calls the data flow processing class of the first language to asynchronously read the data generated during the execution process to obtain the execution result of the external command. According to the above content, it can be known that the present application can realize the seamless calling of the external command of the second language through the first language through the above content, which reduces the cumbersomeness of the interaction between the first language and the second language, including the smooth progress of system control and resource management, and, by seamlessly calling the external command of the second language through the first language, the efficiency of inter-process communication and error handling is improved, and the flexibility of process processing is improved; further, by calling the data flow processing class of the first language to asynchronously read the data generated during the execution process, the data processing efficiency for the external command is improved, and the real-time acquisition of the data generated during the execution process is realized, avoiding the program blocking caused by synchronous waiting for output.
[0118] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0119] Based on the same inventive concept, the embodiment of the present application also provides a command execution device for implementing the command execution method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more command execution device embodiments provided below can refer to the limitations on the command execution method above, and will not be repeated here.
[0120] In one embodiment, as shown in FIG6 , a command execution device is provided, including: an acquisition module 10, a first calling module 20, and a second calling module 30, wherein:
[0121] An acquisition module 10 is used to acquire command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter passed to the external command;
[0122] A first calling module 20, for calling a command execution class instance of a first language according to command parameters to execute an external command of a second language;
[0123] The second calling module 30 is used to call the data stream processing class of the first language during the execution of the external command, and asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0124] In one embodiment, based on the command parameters, the runProcess auxiliary method inside the executeCommand method of the execution command is called according to the LocalCommandExecutorImpl class instance to execute the external command in the second language.
[0125] In one embodiment, the timeout period is determined based on the execution time of the historical commands;
[0126] Based on the command parameters and timeout period, the runProcess auxiliary method inside the executeCommand method of the LocalCommandExecutorImpl class is called to execute the external command of the second language.
[0127] In one embodiment, during the execution of the external command, a data stream processing class of the first language is called to asynchronously read data generated during the execution;
[0128] The result processing class of the first language is called to encapsulate the read data and obtain the execution result of the external command.
[0129] In one embodiment, the abnormal information generated during the execution of the external command is logged.
[0130] In one embodiment, when the external command is executed, the processing process corresponding to the external command is destroyed.
[0131] The command execution device acquires the command parameters of the external command based on the second language, calls the command execution class instance of the first language according to the command parameters, executes the external command of the second language, and then calls the data flow processing class of the first language to asynchronously read the data generated during the execution process to obtain the execution result of the external command. According to the above content, the present application can realize the seamless calling of the external command of the second language through the first language through the above content, which reduces the cumbersomeness of the interaction between the first language and the second language, including the smooth progress of system control and resource management, and the seamless calling of the external command of the second language through the first language improves the efficiency of inter-process communication and error handling, and improves the flexibility of process processing; further, by calling the data flow processing class of the first language to asynchronously read the data generated during the execution process, the data processing efficiency for the external command is improved, and the real-time acquisition of the data generated during the execution process is realized, avoiding the program blocking caused by synchronous waiting for output.
[0132] Each module in the above command execution device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.
[0133] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG7. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner may be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a command execution method is implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0134] Those skilled in the art will understand that the structure shown in FIG. 7 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0135] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0136] Obtaining command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a passing parameter passed to the external command;
[0137] According to the command parameters, the command execution class instance of the first language is called to execute the external command of the second language;
[0138] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0139] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0140] Based on the command parameters, the runProcess auxiliary method inside the executeCommand method of the execution command is called according to the LocalCommandExecutorImpl class instance to execute the external command of the second language.
[0141] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0142] Determine the timeout period based on the execution time of historical commands;
[0143] Based on the command parameters and timeout period, the runProcess auxiliary method inside the executeCommand method of the LocalCommandExecutorImpl class is called to execute the external command of the second language.
[0144] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0145] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution;
[0146] The result processing class of the first language is called to encapsulate the read data and obtain the execution result of the external command.
[0147] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0148] Log the exception information generated during the execution of external commands.
[0149] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0150] When the external command is executed, the processing process corresponding to the external command is destroyed.
[0151] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0152] Obtaining command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a passing parameter passed to the external command;
[0153] According to the command parameters, the command execution class instance of the first language is called to execute the external command of the second language;
[0154] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0155] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0156] Based on the command parameters, the runProcess auxiliary method inside the executeCommand method of the execution command is called according to the LocalCommandExecutorImpl class instance to execute the external command of the second language.
[0157] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0158] Determine the timeout period based on the execution time of historical commands;
[0159] Based on the command parameters and timeout period, the runProcess auxiliary method inside the executeCommand method of the LocalCommandExecutorImpl class is called to execute the external command of the second language.
[0160] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0161] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution;
[0162] The result processing class of the first language is called to encapsulate the read data and obtain the execution result of the external command.
[0163] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0164] Log the exception information generated during the execution of external commands.
[0165] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0166] When the external command is executed, the processing process corresponding to the external command is destroyed.
[0167] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0168] Obtaining command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a passing parameter passed to the external command;
[0169] According to the command parameters, the command execution class instance of the first language is called to execute the external command of the second language;
[0170] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
[0171] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0172] Based on the command parameters, the runProcess auxiliary method inside the executeCommand method of the execution command is called according to the LocalCommandExecutorImpl class instance to execute the external command of the second language.
[0173] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0174] Determine the timeout period based on the execution time of historical commands;
[0175] Based on the command parameters and timeout period, the runProcess auxiliary method inside the executeCommand method of the LocalCommandExecutorImpl class is called to execute the external command of the second language.
[0176] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0177] During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution;
[0178] The result processing class of the first language is called to encapsulate the read data and obtain the execution result of the external command.
[0179] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0180] Log the exception information generated during the execution of external commands.
[0181] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0182] When the external command is executed, the processing process corresponding to the external command is destroyed.
[0183] 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, stored data, displayed data, 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 relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0184] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile 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), magnetoresistive 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. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0185] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, 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 specification.
[0186] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A command execution method, characterized in that: The method comprises: Acquire command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter transferred to the external command; According to the command parameters, calling the command execution class instance of the first language to execute the external command of the second language; During the execution of the external command, the data stream processing class of the first language is called to asynchronously read the data generated during the execution to obtain the execution result of the external command.
2. The method according to claim 1, characterized in that The command execution class instance is a LocalCommandExecutorImpl class instance that implements the local command executor; The step of calling the command execution class instance of the first language according to the command parameter to execute the external command of the second language includes: Based on the command parameters, the runProcess auxiliary method inside the executeCommand method of the execution command is called according to the LocalCommandExecutorImpl class instance to execute the external command of the second language.
3. The method according to claim 2, characterized in that Based on the command parameters, calling the runProcess auxiliary method in the executeCommand method according to the LocalCommandExecutorImpl class instance to execute the external command in the second language includes: Determine the timeout period based on the execution time of historical commands; Based on the command parameters and the timeout period, the runProcess auxiliary method in the executeCommand method is called according to the LocalCommandExecutorImpl class instance to execute the external command in the second language.
4. The method according to claim 1, characterized in that: During the execution of the external command, calling the data stream processing class of the first language and asynchronously reading the data generated during the execution to obtain the execution result of the external command includes: During the execution of the external command, calling the data stream processing class of the first language to asynchronously read the data generated during the execution; The result processing class of the first language is called to encapsulate the read data to obtain the execution result of the external command.
5. The method according to claim 1, characterized in that The method further comprises: The abnormal information generated during the execution of the external command is recorded in a log.
6. The method according to claim 1, characterized in that The method further comprises: When the external command is executed, the processing process corresponding to the external command is destroyed.
7. A command execution device, characterized in that: The device comprises: An acquisition module, used for acquiring command parameters of an external command based on a second language; wherein the command parameters include an interpreter path, a script file name, and a transfer parameter passed to the external command; A first calling module, used to call the command execution class instance of the first language according to the command parameters to execute the external command of the second language; The second calling module is used to call the data flow processing class of the first language during the execution of the external command, and asynchronously read the data generated during the execution to obtain the execution result of the external command.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.