CN103744675A - Engine and method for executing scripts and commands based on Linux pipeline technology - Google Patents

Engine and method for executing scripts and commands based on Linux pipeline technology Download PDF

Info

Publication number
CN103744675A
CN103744675A CN201410005349.4A CN201410005349A CN103744675A CN 103744675 A CN103744675 A CN 103744675A CN 201410005349 A CN201410005349 A CN 201410005349A CN 103744675 A CN103744675 A CN 103744675A
Authority
CN
China
Prior art keywords
engine
parameter
script
length
executable program
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
CN201410005349.4A
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.)
Inspur Beijing Electronic Information Industry Co Ltd
Original Assignee
Inspur Beijing Electronic Information Industry 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 Inspur Beijing Electronic Information Industry Co Ltd filed Critical Inspur Beijing Electronic Information Industry Co Ltd
Priority to CN201410005349.4A priority Critical patent/CN103744675A/en
Publication of CN103744675A publication Critical patent/CN103744675A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention provides an engine and a method for executing scripts and commands based on a Linux pipeline technology. The engine and the method are applied to the field of computer software. The method comprises the following steps: transmitting name parameters of scripts and commands to be executed or name parameters of executable programs to the engine; executing the scripts, commands or the executable programs by the engine and outputting execution results and exit codes. Due to the implementation of the engine and the method, more accurate control of the execution of the scripts, commands or the executable programs can be realized.

Description

A kind of script, command execution engine and method based on Linux pipe technology
Technical field
The present invention relates to computer software fields, relate in particular to a kind of script, command execution engine and method based on Linux pipe technology.
Background technology
At present, in (SuSE) Linux OS, can carry out script, order or executable program by various shell interpreters; In code rank, also can carry out by system call interfaces; Yet in some cases, these two kinds of modes all cannot be controlled accurately to the process of carrying out.
Such as: in a certain program, another one script or order have been carried out, this script or order are used for exporting the content of a file, when this document content is a lot, just be easy to cause buffer overflow, cause program crashing, caused great hidden danger also to the security of the even whole computer system of program; For another example, when carrying out some orders, may wish this order or execute in official hour, or forcing to finish the execution of this order, and do not wait, do not treat, this cannot accomplish in the prior art again; In addition, in existing executive mode, also cannot directly export the code that exits of script, order or executable program.Visible, existing technology is to exist to improve part.
Summary of the invention
The invention provides a kind of script, command execution engine and method based on Linux pipe technology, to address the above problem.
The invention provides a kind of script, command execution engine based on Linux pipe technology, comprising:
Transmit pending script name parameter, command name parameter or executable program name parameter to engine;
Described engine is carried out script, order or executable program and is exported execution result and exit code.
The present invention also provides a kind of script command manner of execution based on Linux pipe technology, comprises the following steps:
Create unnamed pipe for the communication between father and son's process;
Described subprocess close unnamed pipe read hold filec descriptor and standard output, standard error output redirection write after end to unnamed pipe, the reflection of subprocess is replaced with to the reflection of shell interpreter and carries out script, order or executable program;
Described parent process is closed the end of reading that end reads unnamed pipe after filec descriptor of writing of unnamed pipe, and according to preset strategy, the result that output is read and subprocess exit code or error message.
By implementing technical scheme of the present invention, can realize the execution of script, order or executable program is controlled more accurately: can carry out script, order or binary executable, the maximum length of execution result can be set, can control time-out time, one group of process can be finished, the code that exits of script, order or binary executable can be returned to; The present invention also provides function call interface, to realize directly at Calling; The present invention has disclosed the implementation method of this engine simultaneously, uses this engine, can control more accurately the execution of script, order or executable program.
Accompanying drawing explanation
Accompanying drawing described herein is used to provide a further understanding of the present invention, forms the application's a part, and schematic description and description of the present invention is used for explaining the present invention, does not form inappropriate limitation of the present invention.In the accompanying drawings:
The script command that Figure 1 shows that embodiments of the invention 1 is carried out engine implementation schematic diagram;
Figure 2 shows that the script command manner of execution process flow diagram of embodiments of the invention 2.
Embodiment
Hereinafter with reference to accompanying drawing, also describe the present invention in detail in conjunction with the embodiments.It should be noted that, in the situation that not conflicting, embodiment and the feature in embodiment in the application can combine mutually.
The invention provides a kind of script, command execution engine based on Linux pipe technology, comprising:
Transmit pending script name parameter, command name parameter or executable program name parameter to engine;
Described engine is carried out script, order or executable program and is exported execution result and exit code.
Wherein, transmit pending script name parameter, command name parameter or executable program name parameter to engine and maximum is set and return results length parameter; Described engine is carried out script, order or executable program, if the result length of returning is greater than the maximum of setting, returns results length parameter, output error message, otherwise by execution result with exit code printing output.
Wherein, transmit pending script name parameter, command name parameter or executable program name parameter to engine and time-out time parameter is set; Described engine is carried out script, order or executable program, if fail in the time-out time arranging completely, finishes it and carries out, and return to error message, otherwise by execution result with exit code printing output.
Wherein, transmit pending script name parameter, command name parameter or executable program name parameter to engine and maximum is set and return results length parameter and time-out time parameter; Described engine is carried out script, order or executable program, if the result length of returning is greater than the maximum of setting and returns results length parameter or fail in the time-out time arranging complete, export corresponding error message, otherwise by execution result with exit code printing output.
Wherein, described engine provides function call interface, while calling this function, need to return results length parameter and time-out time parameter for this function passes needs name parameter, the maximum of execution script, order or executable program;
Described function is carried out script, order or executable program, and returns to the result of execution and exit code.
The present invention also provides a kind of script command manner of execution based on Linux pipe technology, comprises the following steps:
Create unnamed pipe for the communication between father and son's process;
Described subprocess close unnamed pipe read hold filec descriptor and standard output, standard error output redirection write after end to unnamed pipe, the reflection of subprocess is replaced with to the reflection of shell interpreter and carries out script, order or executable program;
Described parent process is closed the end of reading that end reads unnamed pipe after filec descriptor of writing of unnamed pipe, and according to preset strategy, the result that output is read and subprocess exit code or error message.
Wherein, parent process is closed writing end filec descriptor and setting an alarm clock signal of unnamed pipe, and alarm time length is time-out time parameter;
Described parent process reads the end of reading of unnamed pipe, if parent process is reading before pipeline content completes, receives alarm clock signal, and explanation is carried out overtimely, and parent process sends end signal by the signal process function of registration to subprocess, finishes the execution of subprocess; If after parent process reads pipeline content and completes, not yet receive alarm clock signal, illustrate carry out not overtime.
Wherein, parent process is closed writing end filec descriptor and setting maximum and return results length parameter of unnamed pipe; Parent process is added up the length of the data that read from pipeline, if this length is greater than maximum, returns results length parameter, and the result that explanation is carried out has surpassed the maximum length arranging, and finishes the execution of subprocess; If read in parent process after the content of pipeline, the data length that parent process reads does not surpass the maximum length that returns results, and illustrates that result length meets the requirements.
What wherein, parent process was closed unnamed pipe reads to hold filec descriptor; Parent process is obtained the code that exits of subprocess; Parent process is exported the code printing that exits of the result reading and subprocess; Parent process exits.
Script command based on Linux pipe technology of the present invention is carried out the principle that realizes of engine, in conjunction with Fig. 1, is described below:
1) engine can be accepted three parameters, is respectively maximum and returns results length parameter, time-out time parameter and need execution script, order or executable program name parameter;
2) create one for depositing the buffer area of execution result, size is the maximum specified byte number of length parameter that returns results;
3) create a unnamed pipe, for interprocess communication;
4) create a new process, so just have father, two processes of son;
5) the process group ID of two processes is set to the process ID of parent process, and parent process just becomes the group leader of this process group like this;
6) what subprocess was closed unnamed pipe reads to hold filec descriptor;
7) subprocess by standard output, standard error output redirection the end of writing to unnamed pipe;
8) what subprocess was closed unnamed pipe writes end filec descriptor;
9) subprocess is replaced existing process image with the process image of shell interpreter, and the command parameter that needs are carried out passes to this new process image; After needs execution script, order or executable program are carried out and are finished, this subprocess with and finish;
10) when subprocess carries out above operation, parent process is carried out a series of operation simultaneously, and first, what parent process was closed unnamed pipe writes end filec descriptor;
11) parent process is set an alarm clock signal, and alarm time length is time-out time parameter, and is arranged on the being operating as signal that sends an end process execution that cannot catch to subprocess while receiving this signal, to finish the execution of subprocess;
12) parent process reads the end of reading of unnamed pipe, if there is no data in this pipeline, at this obstruction;
13) if read before pipeline content completes in parent process, receive alarm clock signal, explanation is carried out overtimely, and parent process sends end signal by the signal process function of registration to subprocess, finishes the execution of subprocess;
14) if after parent process reads pipeline content and completes, not yet receive alarm clock signal, illustrate carry out not overtime;
15) carry out with step 14), parent process is added up the length of the data that read from pipeline, if this length is greater than maximum, returns results length parameter simultaneously, and the result that explanation is carried out has surpassed the maximum length arranging, and finishes the execution of subprocess;
16), if read in parent process after the content of pipeline, the data length that parent process reads does not surpass the maximum length that returns results, and illustrates that result length meets the requirements;
17) what parent process was closed unnamed pipe reads to hold filec descriptor;
18) parent process is obtained the code that exits of subprocess;
19) parent process is exported the code printing that exits of the result reading and subprocess;
20) parent process exits.
In addition, the present invention is packaged into function by above-mentioned steps simultaneously, for directly using at Calling.
Below in conjunction with specific embodiment, technical scheme of the present invention is elaborated:
Embodiment mono-:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, can carry out script, use step to be:
1) for this engine transmission, need execution script name parameter, and return results length and time-out time parameter without maximum;
2) engine is carried out script, and by execution result with exit code printing output.
Embodiment bis-:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, can fill order, use step to be:
1) the command name parameter that need to carry out for this engine transmission, and return results length and time-out time parameter without maximum;
2) engine fill order, and by execution result with exit code printing output.
Embodiment tri-:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, can carry out executable program, use step to be:
1) the executable program name parameter that need to carry out for this engine transmission, and return results length and time-out time parameter without maximum;
2) engine is carried out executable program, and by execution result with exit code printing output.
Embodiment tetra-:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, can carry out script, order or executable program, maximum can be set and return results length, use step to be:
1) for this engine transmission, need the name parameter of execution script, order or executable program, and maximum is set returns results length parameter;
2) engine is carried out script, order or executable program, if the result length of returning is greater than the maximum of setting, returns results length parameter, output error message, otherwise by execution result with exit code printing output.
Embodiment five:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, can carry out script, order or executable program, time-out time can be set, use step to be:
1) for this engine transmission, need the name parameter of execution script, order or executable program, and time-out time parameter is set;
2) engine is carried out script, order or executable program, if fail in the time-out time arranging completely, finish it and carry out, and return to error message, otherwise by execution result with exit code printing output.
Embodiment six:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, can carry out script, order or executable program, maximum can be set and return results length and time-out time, use step to be:
1) for this engine transmission, need the name parameter of execution script, order or executable program, and maximum is set returns results length parameter and time-out time parameter;
2) engine is carried out script, order or executable program, if the result length of returning is greater than the maximum of setting and returns results length parameter or fail in the time-out time arranging complete, export corresponding error message, otherwise by execution result with exit code printing output.
Embodiment seven:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, can carry out script, order or executable program, can return to the code that exits after script, order or executable program execution, use step to be:
1) for this engine transmission, need the name parameter of execution script, order or executable program;
2) engine is carried out script, order or executable program, and exports the result of carrying out and exit code.
Embodiment eight:
For a kind of script command based on Linux pipe technology of the present invention, carry out engine, function call interface be provided simultaneously, use step to be:
1) for this function call interface transmission, need the name parameter of execution script, order or executable program;
2) function is carried out script, order or executable program, and returns to the result of execution and exit code.
The script command manner of execution process flow diagram that Figure 2 shows that embodiments of the invention 2, comprises the following steps:
Step 201: transmit pending script name parameter, command name parameter or executable program name parameter to engine;
Step 202: described engine is carried out script, order or executable program and exported execution result and exit code.
By implementing technical scheme of the present invention, realized the execution of script, order or executable program has been controlled more accurately: can carry out script, order or binary executable, the maximum length of execution result can be set, can control time-out time, one group of process can be finished, the code that exits of script, order or binary executable can be returned to; The present invention also provides function call interface, to realize directly at Calling; The present invention has disclosed the implementation method of this engine simultaneously, uses this engine, can control more accurately the execution of script, order or executable program.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.

Claims (9)

1. the script based on Linux pipe technology, a command execution engine, is characterized in that, comprising:
Transmit pending script name parameter, command name parameter or executable program name parameter to engine;
Described engine is carried out script, order or executable program and is exported execution result and exit code.
2. engine according to claim 1, is characterized in that:
Transmit pending script name parameter, command name parameter or executable program name parameter to engine and maximum is set and return results length parameter; Described engine is carried out script, order or executable program, if the result length of returning is greater than the maximum of setting, returns results length parameter, output error message, otherwise by execution result with exit code printing output.
3. engine according to claim 1, is characterized in that:
Transmit pending script name parameter, command name parameter or executable program name parameter to engine and time-out time parameter is set; Described engine is carried out script, order or executable program, if fail in the time-out time arranging completely, finishes it and carries out, and return to error message, otherwise by execution result with exit code printing output.
4. engine according to claim 1, is characterized in that:
Transmit pending script name parameter, command name parameter or executable program name parameter to engine and maximum is set and return results length parameter and time-out time parameter; Described engine is carried out script, order or executable program, if the result length of returning is greater than the maximum of setting and returns results length parameter or fail in the time-out time arranging complete, export corresponding error message, otherwise by execution result with exit code printing output.
5. engine according to claim 1, is characterized in that:
Described engine provides function call interface, while calling this function, need to return results length parameter and time-out time parameter for this function passes needs name parameter, the maximum of execution script, order or executable program;
Described function is carried out script, order or executable program, and returns to the result of execution and exit code.
6. the script command manner of execution based on Linux pipe technology, is characterized in that, comprises the following steps:
Create unnamed pipe for the communication between father and son's process;
Described subprocess close unnamed pipe read hold filec descriptor and standard output, standard error output redirection write after end to unnamed pipe, the reflection of subprocess is replaced with to the reflection of shell interpreter and carries out script, order or executable program;
Described parent process is closed the end of reading that end reads unnamed pipe after filec descriptor of writing of unnamed pipe, and according to preset strategy, the result that output is read and subprocess exit code or error message.
7. method according to claim 5, is characterized in that:
Parent process is closed writing end filec descriptor and setting an alarm clock signal of unnamed pipe, and alarm time length is time-out time parameter;
Described parent process reads the end of reading of unnamed pipe, if parent process is reading before pipeline content completes, receives alarm clock signal, and explanation is carried out overtimely, and parent process sends end signal by the signal process function of registration to subprocess, finishes the execution of subprocess; If after parent process reads pipeline content and completes, not yet receive alarm clock signal, illustrate carry out not overtime.
8. method according to claim 5, is characterized in that:
Parent process is closed writing end filec descriptor and setting maximum and return results length parameter of unnamed pipe;
Parent process is added up the length of the data that read from pipeline, if this length is greater than maximum, returns results length parameter, and the result that explanation is carried out has surpassed the maximum length arranging, and finishes the execution of subprocess; If read in parent process after the content of pipeline, the data length that parent process reads does not surpass the maximum length that returns results, and illustrates that result length meets the requirements.
9. according to the method described in claim 6 or 7, it is characterized in that:
What parent process was closed unnamed pipe reads to hold filec descriptor; Parent process is obtained the code that exits of subprocess; Parent process is exported the code printing that exits of the result reading and subprocess; Parent process exits.
CN201410005349.4A 2014-01-06 2014-01-06 Engine and method for executing scripts and commands based on Linux pipeline technology Pending CN103744675A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410005349.4A CN103744675A (en) 2014-01-06 2014-01-06 Engine and method for executing scripts and commands based on Linux pipeline technology

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410005349.4A CN103744675A (en) 2014-01-06 2014-01-06 Engine and method for executing scripts and commands based on Linux pipeline technology

Publications (1)

Publication Number Publication Date
CN103744675A true CN103744675A (en) 2014-04-23

Family

ID=50501695

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410005349.4A Pending CN103744675A (en) 2014-01-06 2014-01-06 Engine and method for executing scripts and commands based on Linux pipeline technology

Country Status (1)

Country Link
CN (1) CN103744675A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104090817A (en) * 2014-07-15 2014-10-08 浪潮电子信息产业股份有限公司 Processing method for linux shell script parallel execution and timeout automatic exit
CN105760306A (en) * 2016-03-10 2016-07-13 上海斐讯数据通信技术有限公司 Command issuing method and system and debugging method
CN109740342A (en) * 2018-12-20 2019-05-10 深圳市网心科技有限公司 Obtain method, system, computer installation and storage medium that shell executes permission
CN111078382A (en) * 2019-12-17 2020-04-28 中国建设银行股份有限公司 Command timeout processing method and device
CN111694616A (en) * 2019-03-12 2020-09-22 福建天晴在线互动科技有限公司 Method for acquiring command execution result and computer-readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1516010A (en) * 2003-01-02 2004-07-28 联想(北京)有限公司 Method for accurately controlling external program
US7003765B1 (en) * 2001-12-12 2006-02-21 Oracle International Corporation Computer-based pre-execution analysis and verification utility for shell scripts
CN101082870A (en) * 2007-07-20 2007-12-05 中兴通讯股份有限公司 Method for restricting parallel execution of shell script
CN101727390A (en) * 2009-12-28 2010-06-09 金蝶软件(中国)有限公司 Method and device for debugging performance test scripts

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7003765B1 (en) * 2001-12-12 2006-02-21 Oracle International Corporation Computer-based pre-execution analysis and verification utility for shell scripts
CN1516010A (en) * 2003-01-02 2004-07-28 联想(北京)有限公司 Method for accurately controlling external program
CN101082870A (en) * 2007-07-20 2007-12-05 中兴通讯股份有限公司 Method for restricting parallel execution of shell script
CN101727390A (en) * 2009-12-28 2010-06-09 金蝶软件(中国)有限公司 Method and device for debugging performance test scripts

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
JOSEPH J.BAMBARA 等: "《SQL Server开发指南》", 31 August 2000, 北京:电子工业出版社 *
王东亮: "防灾安全监控系统中脚本命令的设计与实现", 《中国优秀硕士学位论文全文数据库信息科技辑》 *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104090817A (en) * 2014-07-15 2014-10-08 浪潮电子信息产业股份有限公司 Processing method for linux shell script parallel execution and timeout automatic exit
CN105760306A (en) * 2016-03-10 2016-07-13 上海斐讯数据通信技术有限公司 Command issuing method and system and debugging method
CN109740342A (en) * 2018-12-20 2019-05-10 深圳市网心科技有限公司 Obtain method, system, computer installation and storage medium that shell executes permission
CN109740342B (en) * 2018-12-20 2021-08-06 深圳市网心科技有限公司 Method, system, computer device and storage medium for acquiring shell execution permission
CN111694616A (en) * 2019-03-12 2020-09-22 福建天晴在线互动科技有限公司 Method for acquiring command execution result and computer-readable storage medium
CN111078382A (en) * 2019-12-17 2020-04-28 中国建设银行股份有限公司 Command timeout processing method and device
CN111078382B (en) * 2019-12-17 2024-06-21 中国建设银行股份有限公司 Command overtime processing method and device

Similar Documents

Publication Publication Date Title
CN107977268B (en) Task scheduling method and device for artificial intelligence heterogeneous hardware and readable medium
CN103744675A (en) Engine and method for executing scripts and commands based on Linux pipeline technology
US10846124B2 (en) Communication method, apparatus and system for virtual machine and host machine
CN107077435B (en) Device driver registration apparatus and device driver registration method using the same
CN104932972B (en) A kind of method and device of reaction state debugging utility
US20100146254A1 (en) Method for binarizing initial script on operating system and operating method of binary script
KR100654428B1 (en) System for improving transaction rate of java program and method thereof
US8806453B1 (en) Integrating disparate programming languages to form a new programming language
CN114546394B (en) Unified Internet of things peripheral access and control method
CN106469051B (en) Object delivery method and device
KR20150124530A (en) Application build system, control method thereof, and recording medium for recording program for executing the control method
US20160196170A1 (en) Integrated-circuit radio
US20140189669A1 (en) Dynamic timeout determination for microcontroller management of firmware updates
US20160321092A1 (en) Computer system and method for accessing virtual machine
JP2008065823A (en) Method for improving communication speed of hid device
US10095209B2 (en) Programming system for device control
CN111858020B (en) User resource limiting method and device and computer storage medium
US10545729B2 (en) Computer program interface
US10310874B2 (en) Formal objects and executors
CN109358850A (en) The intelligence programming implementation method and device that a kind of pair of system setting is written and read
KR20160102040A (en) Integrated-circuit radio
US11169783B2 (en) System and method for generating an executable hardware-software interface specification
US20170139970A1 (en) Method for updating a record in a database by a data- processing device
CN110489121B (en) Skin package file generation method and system
KR101858565B1 (en) Independent parallel processing method for massive data in distributed platform and system of thereof

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20140423

WD01 Invention patent application deemed withdrawn after publication