CN111694616A - Method for acquiring command execution result and computer-readable storage medium - Google Patents

Method for acquiring command execution result and computer-readable storage medium Download PDF

Info

Publication number
CN111694616A
CN111694616A CN201910183539.8A CN201910183539A CN111694616A CN 111694616 A CN111694616 A CN 111694616A CN 201910183539 A CN201910183539 A CN 201910183539A CN 111694616 A CN111694616 A CN 111694616A
Authority
CN
China
Prior art keywords
result
command
file
mark
return value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910183539.8A
Other languages
Chinese (zh)
Inventor
刘德建
林清福
何巍巍
陈宏展
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian Tianqing Online Interactive Technology Co Ltd
Original Assignee
Fujian Tianqing Online Interactive Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian Tianqing Online Interactive Technology Co Ltd filed Critical Fujian Tianqing Online Interactive Technology Co Ltd
Priority to CN201910183539.8A priority Critical patent/CN111694616A/en
Publication of CN111694616A publication Critical patent/CN111694616A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Retry When Errors Occur (AREA)

Abstract

The invention discloses a method for acquiring command execution results and a computer readable storage medium, wherein the method comprises the following steps: storing a target command to be executed into a preset script file; executing the script file to obtain a command return value; storing a result mark corresponding to the command return value into a preset result file; and judging the command execution result according to the result mark in the result file. The invention can accurately and effectively acquire the command execution result.

Description

Method for acquiring command execution result and computer-readable storage medium
Technical Field
The present invention relates to the field of software technologies, and in particular, to a method for obtaining a command execution result and a computer-readable storage medium.
Background
In some programs in the linux system, due to business requirements, for example, when other programs are started by creating a subprocess in the programs, in order to acquire a subprocess exit state and prevent a zombie process from occurring due to the fact that a factor process exits, a processing function needs to be assigned to a SIGCHLD signal when the programs are started, the function receives the exited subprocess by calling waitpid, releases resources occupied by the subprocess, and returns to the subprocess exit state; in such a program, when a command is executed using an interface such as system, there are many problems such as that the command is normally executed and the system function returns to-1. This is because the sub-process PID is captured outside, resulting in no sub-process being captured inside the system, returning to-1; in this case, it is impossible to determine whether or not the command is normally executed in the program.
The main treatment methods at present are:
sighandler_t old_handler;
old_handler=signal(SIGCHLD,SIG_DFL);
ret=system(cmd_line);
signal(SIGCHLD,old_handler);
the processing mode means that the SIGCHLD signal is set as default processing before the command is executed, a processing function pointer of the prior SIGCHLD signal is acquired, and after the command is executed, the SIGCHLD signal is set back to the original processing function. However, if a child process exits before the program sets the SIGCHLD signal back to the previous processing function, the parent process cannot trap. Therefore, there is currently no good solution.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: provided are a method for acquiring a command execution result and a computer-readable storage medium, which can accurately and efficiently acquire the command execution result.
In order to solve the technical problems, the invention adopts the technical scheme that: a method for acquiring command execution results comprises the following steps:
storing a target command to be executed into a preset script file;
executing the script file to obtain a command return value;
storing a result mark corresponding to the command return value into a preset result file;
and judging the command execution result according to the result mark in the result file.
The invention also relates to a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of:
storing a target command to be executed into a preset script file;
executing the script file to obtain a command return value;
storing a result mark corresponding to the command return value into a preset result file;
and judging the command execution result according to the result mark in the result file.
The invention has the beneficial effects that: the command is stored in the script, the purpose of executing the command is achieved by executing the script, after the command is executed, the result mark corresponding to the command return value is output to another file, the result mark is prevented from being mixed with the standard output content when the command is executed, the judgment is prevented from being influenced, and therefore the situation that whether the command is normally executed or not can not be judged by a program due to the problem of function return values of systems and the like can be avoided. The invention can accurately and effectively acquire the command execution result.
Drawings
Fig. 1 is a flowchart of a method for obtaining a command execution result according to a first embodiment of the present invention.
Detailed Description
In order to explain technical contents, objects and effects of the present invention in detail, the following detailed description is given with reference to the accompanying drawings in conjunction with the embodiments.
The most key concept of the invention is as follows: saving the command in the script, and executing the command by executing the script; and outputting a result mark corresponding to the command return value to another file.
Referring to fig. 1, a method for obtaining a command execution result includes:
storing a target command to be executed into a preset script file;
executing the script file to obtain a command return value;
storing a result mark corresponding to the command return value into a preset result file;
and judging the command execution result according to the result mark in the result file.
From the above description, the beneficial effects of the present invention are: the command execution result can be accurately and effectively acquired.
Further, the storing the result flag corresponding to the command return value into a preset result file specifically includes:
if the command return value is zero, storing a first result mark into a preset result file;
and if the command return value is not zero, storing a second result mark into a preset result file.
Further, if the result flag in the result file is the first result flag, it is determined that the command is successfully executed;
and if the result mark in the result file is the second result mark, judging that the command execution fails.
As can be seen from the above description, by outputting the result flag corresponding to the command return value to another file, the result flag is prevented from being mixed with the standard output content when the command is executed, which affects the judgment, and thus the accuracy of obtaining the command execution result is ensured.
Further, the script file is a shell script file.
The invention also proposes a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of:
storing a target command to be executed into a preset script file;
executing the script file to obtain a command return value;
storing a result mark corresponding to the command return value into a preset result file;
and judging the command execution result according to the result mark in the result file.
Further, the storing the result flag corresponding to the command return value into a preset result file specifically includes:
if the command return value is zero, storing a first result mark into a preset result file;
and if the command return value is not zero, storing a second result mark into a preset result file.
Further, the determining, according to the result flag in the result file, the command execution result specifically includes:
if the result mark in the result file is the first result mark, judging that the command is successfully executed;
and if the result mark in the result file is the second result mark, judging that the command execution fails.
Further, the script file is a shell script file.
Example one
Referring to fig. 1, a first embodiment of the present invention is: a method for acquiring command execution results is based on a linux system and comprises the following steps:
s1: storing a target command to be executed into a preset script file; the script file is a shell script file.
S2: executing the script file to obtain a command return value; in particular, a system function may be used to execute a "shell.
S3: and storing the result mark corresponding to the command return value into a preset result file. Specifically, if the command return value is zero, saving a first result flag to a preset result file; and if the command return value is not zero, storing a second result mark into a preset result file.
For example, in a shell script, get the return value ($? Is 0, save the first result flag [ succ ] to the result file result. log, if return the value $? If not, saving the second result flag [ fail ] to the result file result.
S4: and judging the command execution result according to the result mark in the result file. Specifically, the content in the result file result.log is read, and if the first result flag [ succ ] is read, the command execution is determined to be successful; if the second result flag [ fail ] is read, the command execution is determined to have failed.
In an actual application scenario, taking the execution of the decompression command as an example, the following codes are used to implement:
tar-zxvf/XXX/build.tar.gz–c/XXX/
if[$?-ne 0];then
echo“[fail]”>>/XXX/result.log
else
echo“[succ]”>>/XXX/result.log
fi
the first sentence in the above codes is a decompression command, $? Is script is a command return value, default $? Log is result file, where 0 represents command execution success, and non-0 represents command execution failure.
By outputting the result mark corresponding to the command return value to another file after the command is executed instead of directly outputting, the result mark is prevented from being mixed with the standard output content when the command is executed, and judgment is influenced.
Example two
The present embodiment is a computer-readable storage medium corresponding to the above-mentioned embodiments, on which a computer program is stored, which when executed by a processor, performs the steps of:
storing a target command to be executed into a preset script file;
executing the script file to obtain a command return value;
storing a result mark corresponding to the command return value into a preset result file;
and judging the command execution result according to the result mark in the result file.
Further, the storing the result flag corresponding to the command return value into a preset result file specifically includes:
if the command return value is zero, storing a first result mark into a preset result file;
and if the command return value is not zero, storing a second result mark into a preset result file.
Further, the determining, according to the result flag in the result file, the command execution result specifically includes:
if the result mark in the result file is the first result mark, judging that the command is successfully executed;
and if the result mark in the result file is the second result mark, judging that the command execution fails.
Further, the script file is a shell script file.
In summary, the method for obtaining the command execution result and the computer readable storage medium provided by the present invention store the command in the script, and achieve the purpose of executing the command by executing the script, and after the command is executed, output the result flag corresponding to the command return value to another file, so as to prevent the result flag from mixing with the standard output content when executing the command, which affects the judgment, thereby avoiding the problem that the program cannot judge whether the command is normally executed due to the function return value such as system. The invention can accurately and effectively acquire the command execution result.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (8)

1. A method for obtaining command execution results is characterized by comprising the following steps:
storing a target command to be executed into a preset script file;
executing the script file to obtain a command return value;
storing a result mark corresponding to the command return value into a preset result file;
and judging the command execution result according to the result mark in the result file.
2. The method according to claim 1, wherein the step of saving the result flag corresponding to the command return value in a preset result file specifically comprises:
if the command return value is zero, storing a first result mark into a preset result file;
and if the command return value is not zero, storing a second result mark into a preset result file.
3. The method according to claim 2, wherein the determining, according to the result flag in the result file, the command execution result specifically includes:
if the result mark in the result file is the first result mark, judging that the command is successfully executed;
and if the result mark in the result file is the second result mark, judging that the command execution fails.
4. The method according to claim 1, wherein the script file is a shell script file.
5. A computer-readable storage medium, on which a computer program is stored, which program, when executed by a processor, carries out the steps of:
storing a target command to be executed into a preset script file;
executing the script file to obtain a command return value;
storing a result mark corresponding to the command return value into a preset result file;
and judging the command execution result according to the result mark in the result file.
6. The computer-readable storage medium according to claim 5, wherein the saving of the result flag corresponding to the command return value to a preset result file specifically includes:
if the command return value is zero, storing a first result mark into a preset result file;
and if the command return value is not zero, storing a second result mark into a preset result file.
7. The computer-readable storage medium according to claim 6, wherein the determining, according to the result flag in the result file, the command execution result specifically comprises:
if the result mark in the result file is the first result mark, judging that the command is successfully executed;
and if the result mark in the result file is the second result mark, judging that the command execution fails.
8. The computer-readable storage medium of claim 5, wherein the script file is a shell script file.
CN201910183539.8A 2019-03-12 2019-03-12 Method for acquiring command execution result and computer-readable storage medium Pending CN111694616A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910183539.8A CN111694616A (en) 2019-03-12 2019-03-12 Method for acquiring command execution result and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910183539.8A CN111694616A (en) 2019-03-12 2019-03-12 Method for acquiring command execution result and computer-readable storage medium

Publications (1)

Publication Number Publication Date
CN111694616A true CN111694616A (en) 2020-09-22

Family

ID=72475248

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910183539.8A Pending CN111694616A (en) 2019-03-12 2019-03-12 Method for acquiring command execution result and computer-readable storage medium

Country Status (1)

Country Link
CN (1) CN111694616A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113391942A (en) * 2021-06-18 2021-09-14 华云数据控股集团有限公司 Shell script log printing method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101630262A (en) * 2009-07-17 2010-01-20 北京数帅科技有限公司 Method for monitoring and controlling subprocess based on Linux system
CN103744675A (en) * 2014-01-06 2014-04-23 浪潮(北京)电子信息产业有限公司 Engine and method for executing scripts and commands based on Linux pipeline technology
US20160062799A1 (en) * 2014-09-02 2016-03-03 Ab Initio Technology Llc Managing invocation of tasks
CN105389255A (en) * 2015-10-21 2016-03-09 浪潮电子信息产业股份有限公司 Automatic test method for comparing BMC OEM command return value with fixed information

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101630262A (en) * 2009-07-17 2010-01-20 北京数帅科技有限公司 Method for monitoring and controlling subprocess based on Linux system
CN103744675A (en) * 2014-01-06 2014-04-23 浪潮(北京)电子信息产业有限公司 Engine and method for executing scripts and commands based on Linux pipeline technology
US20160062799A1 (en) * 2014-09-02 2016-03-03 Ab Initio Technology Llc Managing invocation of tasks
CN105389255A (en) * 2015-10-21 2016-03-09 浪潮电子信息产业股份有限公司 Automatic test method for comparing BMC OEM command return value with fixed information

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113391942A (en) * 2021-06-18 2021-09-14 华云数据控股集团有限公司 Shell script log printing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111612468B (en) Method and device for transmitting transaction information and identifying consensus
CN108804215B (en) Task processing method and device and electronic equipment
CN111290806B (en) Calling method and device of application program interface, computer equipment and storage medium
US5301311A (en) Control method for preventing incorrect reset of common resource and multicomputer system executing the method
CN110308880B (en) Log printing method, system, computer device and computer readable storage medium
CN111949513A (en) Configuration file loading method and device, electronic equipment and readable storage device
CN111694616A (en) Method for acquiring command execution result and computer-readable storage medium
KR101710328B1 (en) Os security kernel system supporting dynamic reconfiguration and change and method thereof
CN109739487B (en) Business logic processing method and device and computer readable storage medium
CN111443902A (en) Function call tree generation method, system, computer device and readable storage medium
CN109032612B (en) Interface calling method and device of hybrid application and computer readable storage medium
US10795650B2 (en) Code lineage tool
CN112199272A (en) Intelligent terminal testing method and device, terminal equipment and medium
CN110231921B (en) Log printing method, device, equipment and computer readable storage medium
CN108959915B (en) Rootkit detection method, rootkit detection device and server
US20240168865A1 (en) Exception handling method and apparatus, device, and storage medium
CN115756935A (en) Abnormal fault positioning method, device and equipment of embedded software system
CN110471669B (en) Null pointer reference detection method and detection device
CN114610413A (en) Method, device, equipment and storage medium for executing synchronous and asynchronous tasks based on Java
CN111459819A (en) Software testing method and device, electronic equipment and computer readable medium
CN111984341B (en) Project monitoring method and device, electronic equipment and storage medium
CN113656106B (en) Plug-in loading method, device, electronic equipment and computer readable storage medium
JPH0588933A (en) Parallel processing system with debugging function
CN113448818B (en) Log tracking method, device and medium based on probability
CN108563523B (en) Information callback method, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination