CN104899081A - System and method for calling external executable command on the basis of JAVA technology - Google Patents

System and method for calling external executable command on the basis of JAVA technology Download PDF

Info

Publication number
CN104899081A
CN104899081A CN201410082313.6A CN201410082313A CN104899081A CN 104899081 A CN104899081 A CN 104899081A CN 201410082313 A CN201410082313 A CN 201410082313A CN 104899081 A CN104899081 A CN 104899081A
Authority
CN
China
Prior art keywords
module
external command
output
command
external
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.)
Granted
Application number
CN201410082313.6A
Other languages
Chinese (zh)
Other versions
CN104899081B (en
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.)
Wuxi Tvmining Juyuan Media Technology Co Ltd
Original Assignee
Wuxi Tvmining Juyuan Media 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 Wuxi Tvmining Juyuan Media Technology Co Ltd filed Critical Wuxi Tvmining Juyuan Media Technology Co Ltd
Priority to CN201410082313.6A priority Critical patent/CN104899081B/en
Publication of CN104899081A publication Critical patent/CN104899081A/en
Application granted granted Critical
Publication of CN104899081B publication Critical patent/CN104899081B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention provides a system for calling an external executable command on the basis of the JAVA technology. The system comprises a tool construction module, an attribute setting module, an external command starting module, an output module, a timeout judgment module, a result returning module and a storage module, wherein the tool construction module is used for initializing a system; the attribute setting module is used for setting various parameters required when the system operates; the external command starting module is used for starting an external application command; the output module is used for obtaining and outputting a standard stream and an error stream output by the external command; the timeout judgment module is used for monitoring whether the external command times out and terminates or not; the result returning module is used for returning a system operation result; and the storage module is used for storing data which needs to be stored when the system operates. The invention also provides a method for calling the external executable command on the basis of the JAVA technology.

Description

A kind of system and method calling outside executable command based on JAVA technology
technical field:
The present invention relates to computerese field, relate to a kind of system and the method thereof of calling external command particularly, particularly a kind of system and method calling outside executable command based on JAVA technology.
background technology:
The scheme that JAVA general at present calls outer application system is that the Process class of exec (String s) the method generation of the Runtime class using JAVA inside to provide is to perform external command, simply obtain normal stream and the error flow of external command output, this scheme is no problem under normal circumstances, but below outer application system existence during two kinds of abnormal situations, just there will be the situation that card pauses, delay is even collapsed:
1) execution time surpasss the expectation or seemingly-dead;
2) a large amount of output stream contents is produced when performing.
summary of the invention:
For solving the problems of the technologies described above, the invention provides a kind of system calling outside executable command based on JAVA technology, comprising: Construct Tool module, for initialization system; Attribute setup module, various parameters required during for arranging system cloud gray model; Start external command module, for starting applications order; Output module, for obtain and export external command export normal stream and error flow; Time-out judge module, for monitoring applications order whether time-out and whether stopping; Result returns module, for the operation result of retrieval system; Memory module, needs the data stored for storage system in running.
Preferably, the attribute in described attribute setup module includes, overtime duration threshold values, listen timeout interval, standard/abnormal output stream object, output mode, rreturn value attribute.
Preferably, described startup external command module starts external command by the exec method of the Runtime class in JAVA API.
Preferably, described output module passes through mode outputting standard stream and the error flow of multithreading.
Preferably, the mode of described output module outputting standard stream and error flow is divided into single file to read output and non-single file reads output, when export content less and export content need to select single file reading manner during subsequent calls, when export content more time select non-single file reading manner.
Preferably, described overtime judge module starts timing while above-mentioned startup external command module starts external command, the cycle is spaced apart with listen timeout described in above-mentioned attribute setup module, the return state of said external order is monitored in circulation, if the return state display external system of said external order is finished or return state that exception or said external order occur does not show said external order and is finished within the time of duration threshold values overtime described in above-mentioned attribute setup module, then directly terminate said external order, and call the above results and return module.
On the other hand, the present invention also provides a kind of method calling outside executable command based on JAVA technology, comprising: call constructed fuction; Various property parameters required when initialization system runs; Start applications order; Obtain and export external command export normal stream and error flow; Whether whether the order of monitoring applications is overtime and stop; The operation result of retrieval system.
Preferably, various property parameters required when arranging system cloud gray model, wherein said various parameter comprises and arranges overtime duration threshold values, arranges listen timeout interval, arranges standard/abnormal output stream object, arranges output mode, arranges rreturn value attribute.
Preferably, outside being started by exec (String s) method of the Runtime class in JAVA API
Portion's order.
Preferably, by mode outputting standard stream and the error flow of multithreading.
Preferably, the mode obtaining also outputting standard stream and error flow is divided into single file reading output and the reading of non-single file to export, when export content less and export content need to select single file reading manner during subsequent calls, when export content more time select non-single file reading manner.
Preferably; the cycle is spaced apart with above-mentioned listen timeout; the return state of external command is monitored in circulation; if the return state display external command of said external order is finished or exception occurs or do not show external command within the time of above-mentioned overtime duration threshold values to be finished; then terminate said external order, return operation result.
The present invention is based on java technology and provide a kind of system and method using java language call external executable, and use inquiry mechanism cleverly, interval catch specific exceptions, and dish out multithreading outputting standard stream and error flow, thoroughly solve the seemingly-dead problem of program that external application causes being called a large amount of output stream of generation by java and the execution time problem surpassed the expectation.
accompanying drawing illustrates:
Fig. 1 is the structured flowchart calling the system of outside executable command based on JAVA technology that embodiment of the present invention relates to;
Fig. 2 is the process flow diagram calling the method for outside executable command based on JAVA technology that embodiment of the present invention relates to;
Fig. 3 is the process flow diagram of above-mentioned overtime judge module 4 when running.
embodiment:
Illustrated embodiment sets forth this invention with reference to the accompanying drawings below.
Fig. 1 shows the structured flowchart calling the system of outside executable command based on JAVA technology that embodiment of the present invention relates to.As shown in Figure 1, the above-mentioned system calling outside executable command based on JAVA technology comprises Construct Tool module 1, attribute setup module 2, starts external command module 3, output module 4, overtime judge module 5, result return module 6, memory module 7.Wherein, Construct Tool module 1 for initialization system, various supplemental characteristics required when attribute setup module 2 is for arranging system cloud gray model; Start external command module 3 for starting applications order; Output module 4 for obtain external command export normal stream and error flow and export said external order export normal stream and error flow; Time-out judge module 5 is for monitoring external command whether time-out and judge whether said external order stops; Result returns the operation result of module 6 for retrieval system; Memory module 7 needs the data stored in running for storage system.
In above-mentioned attribute setup module 2, the required supplemental characteristic arranged comprises overtime duration threshold values, listen timeout interval, standard/abnormal output stream object, output mode, rreturn value attribute etc., when system brings into operation, first the above-mentioned parameter data that above-mentioned Construct Tool module 1 is come in the above-mentioned attribute setup module 2 of initialization are called, such as above-mentioned overtime duration threshold values is defaulted as 0, above-mentioned listen timeout interval is defaulted as 0, above-mentioned output mode is defaulted as single file output and above-mentioned rreturn value attribute is defaulted as exception etc., and above-mentioned parameter data are stored in above-mentioned memory module 7, call for other modules.
Above-mentioned startup external command module 3 starts external command by exec (String s) method of the Runtime class in JAVA API, and obtains the example of Process class.The example of described Process class can be used for controlling the process of said external order and obtain relevant information.
The normal stream that above-mentioned output module 4 exports after obtaining said external order operation by the example of the described Process class obtained in above-mentioned startup external command module 3 and error flow, and normal stream obtained above and error flow are stored in above-mentioned initialized standard/abnormal output stream object, then are read respectively in the mode of multithreading by above-mentioned initialized output mode and export described normal stream and error flow.Above-mentioned initialized output mode is defaulted as the way of output (readline) that single file reads, also the way of output that non-single file reads can be adopted, when said external order output content is less and when needing, single file is adopted to read the way of output, when said external order output content is more, then non-single file is adopted to read the way of output.
Above-mentioned overtime judge module 5 starts timing while above-mentioned startup external command module 3 starts external command; the cycle is spaced apart again with listen timeout described in above-mentioned attribute setup module 2; the return state of said external order is monitored in circulation; if the return state display external system of said external order is finished or return state that exception or said external order occur does not show said external order and is finished within the time of duration threshold values overtime described in above-mentioned attribute setup module; then directly terminate said external order, and call the above results and return module.
Fig. 2 is the process flow diagram calling the method for outside executable command based on JAVA technology that embodiment of the present invention relates to.Illustrate in the processing procedure calling outside executable command based on JAVA technology of the present embodiment referring to Fig. 2.
When system brings into operation, first constructed fuction (step S1) is called by above-mentioned Construct Tool module 1, and above-mentioned attribute setup module 2 carries out initialization (step S2) to parameter used in above-mentioned constructed fuction, namely need when the system is operated to carry out initialization (step S2) to parameter used in above-mentioned constructed fuction.Above-mentioned parameter includes overtime duration threshold values, listen timeout interval, standard/abnormal output stream object, output mode, rreturn value attribute etc.Such as, when initialization is carried out to parameter used in above-mentioned constructed fuction, above-mentioned overtime duration threshold values can be defaulted as 0, above-mentioned listen timeout interval is defaulted as 0, above-mentioned output mode is defaulted as single file output and above-mentioned rreturn value attribute is defaulted as exception etc., and above-mentioned parameter is stored in above-mentioned memory module 7.Again by exec (String s) the method call external command of above-mentioned startup external command module 3 by the basic function Runtime class in JAVA API, and obtaining the example of Process class, the example of described Process class can be used for controlling the process of said external order and obtain relevant information (step S3).The normal stream that above-mentioned output module 4 is exported after being run by the external command that the example of above-mentioned Process class obtains being called by above-mentioned startup external command module 3 and error flow, and obtained normal stream and error flow are stored in above-mentioned initialized standard/abnormal output stream object, instantiation two thread objects again, are exported respectively by the ready-made object of two after above-mentioned instantiation and are above-mentionedly stored in standard/abnormal output stream object Plays stream and error flow (step S4).While above-mentioned startup external command module 3 calls external command, start timing, and be spaced apart the cycle with above-mentioned listen timeout, circulated by above-mentioned overtime judge module 5 and monitor returning results of said external order.If returning results of said external order normally to run for external command and not to exceed above-mentioned overtime duration threshold values (step S5: no) working time, then above-mentioned output module 4 continues the error flow and the normal stream that obtain said external order, and exports error flow and the normal stream of said external order.If said external order return results as external command is finished and stop, or external command occurs abnormal and stops, or the time that external command is run has exceeded above-mentioned overtime duration threshold values (step S5: yes), then the above results returns the process that module 6 terminates said external order, finally arranges and returns the operation result (step S6) of said system.
Fig. 3 is the process flow diagram of the overtime judge module 5 of the system of outside executable command of calling based on JAVA technology that embodiment of the present invention relates to when running.Illustrate in the processing procedure calling the overtime judge module of outside executable command based on JAVA technology of the present embodiment referring to Fig. 3.
The overtime duration threshold values n that overtime judge module needs to call is initialized when system brings into operation, listen timeout interval m, timing is started when above-mentioned startup external command module 3 starts to call external command, setting the present timing time is in the present embodiment x(step S51), system with above-mentioned listen timeout interval m for the cycle, circulated by above-mentioned overtime judge module 5 and monitor returning results of said external order, when x % m unequal to=0 (step S52: no), system continues to run above-mentioned output module 4, obtain and export said external order export normal stream and error flow, as x%m==0 (step S52: yes), system obtains returning results (step S53) of said external order by the exitValue () method of above-mentioned Process example.If what above-mentioned overtime judge module 5 judged said external order returns results as external command is finished (step S54: yes), then the above results returns module 6 and terminates external command (step S57).If above-mentioned overtime judge module 5 judges returning results as external command is not finished (step S54: no) of said external order, then judge whether external command exception (step S55) occurs.If above-mentioned overtime judge module 5 judges that external command occurs abnormal (step S55: yes), then the above results returns module 6 and terminates external command (step S57).If above-mentioned overtime judge module 5 judges that exception (step S55: no) does not occur in said external order, then judge whether exceed above-mentioned overtime duration threshold values (step S56) above-mentioned working time.If above-mentioned overtime judge module 5 judges to exceed above-mentioned overtime duration threshold values (step S56: yes) above-mentioned working time, then the above results returns module 6 and terminates external command (step S57).If above-mentioned overtime judge module 5 judges not exceed above-mentioned overtime duration threshold values (step S56: no) above-mentioned working time, then return above-mentioned output module 4.
In the above-described embodiment, above-mentioned overtime judge module 5 judges by the order that is abnormal and whether time-out that whether is finished, whether occurs.But the present invention is not limited to this, also can by whether occur abnormal, whether to be finished and the order of time-out or other order judge.
Embodiment described in above instructions and embodiment should be understood only be not used in for illustration of the present invention and limit the scope of the invention.After having read the present invention, the amendment of those skilled in the art to various equivalents of the present invention has all fallen within the application's claims limited range.

Claims (12)

1., based on the system calling outside executable command of JAVA technology, comprising:
Construct Tool module, for initialization system;
Attribute setup module, various parameters required during for arranging system cloud gray model;
Start external command module, for starting applications order;
Output module, for obtain and export external command export normal stream and error flow;
Time-out judge module, for monitoring applications order whether time-out and whether stopping;
Result returns module, for the operation result of retrieval system;
Memory module, needs the data stored for storage system in running.
2. system according to claim 1, is characterized in that:
Attribute in described attribute setup module comprises overtime duration threshold values, listen timeout interval, standard/abnormal output stream object, output mode, rreturn value attribute.
3. system according to claim 2, is characterized in that:
Described startup external command module starts external command by the exec method of the Runtime class in JAVA API.
4. the system according to claim 1-3, is characterized in that:
Described output module passes through mode outputting standard stream and the error flow of multithreading.
5. system according to claim 4, is characterized in that:
The mode of described output module outputting standard stream and error flow is divided into single file to read output and non-single file reads output, when export content less and export content need to select single file reading manner during subsequent calls, when export content more time select non-single file reading manner.
6. system according to claim 5, is characterized in that:
Described overtime judge module starts timing while described startup external command module starts external command; the cycle is spaced apart with listen timeout described in described attribute setup module; the return state of described external command is monitored in circulation; if the return state display external system of described external command is finished or return state that abnormal or described external command occurs does not show described external command and is finished within the time of duration threshold values overtime described in described attribute setup module; then directly terminate described external command, and call described result and return module.
7., based on the method calling outside executable command of JAVA technology, comprising:
Call constructed fuction;
Various property parameters required when initialization system runs;
Start applications order;
Obtain and export external command export normal stream and error flow;
Whether whether the order of monitoring applications is overtime and stop;
The operation result of retrieval system.
8. method according to claim 7, is characterized in that:
Various property parameters required when arranging system cloud gray model, wherein said property parameters comprises and arranges overtime duration threshold values, arranges listen timeout interval, arranges standard/abnormal output stream object, arranges output mode, arranges rreturn value attribute.
9. method according to claim 8, is characterized in that:
External command is started by the exec method of the Runtime class in JAVA API.
10. the method according to claim 7-9, is characterized in that, also comprises:
By mode outputting standard stream and the error flow of multithreading.
11. methods according to claim 10, is characterized in that:
The mode obtaining also outputting standard stream and error flow is divided into single file reading output and the reading of non-single file to export, when export content less and export content need to select single file reading manner during subsequent calls, when export content more time select non-single file reading manner.
12. methods according to claim 11, is characterized in that:
The cycle is spaced apart with described listen timeout; the return state of external command is monitored in circulation; if the return state display external command of described external command is finished or exception occurs or do not show external command within the time of described overtime duration threshold values to be finished; then terminate described external command, return operation result.
CN201410082313.6A 2014-03-07 2014-03-07 The system and method for executable command outside a kind of calling based on JAVA technologies Expired - Fee Related CN104899081B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410082313.6A CN104899081B (en) 2014-03-07 2014-03-07 The system and method for executable command outside a kind of calling based on JAVA technologies

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410082313.6A CN104899081B (en) 2014-03-07 2014-03-07 The system and method for executable command outside a kind of calling based on JAVA technologies

Publications (2)

Publication Number Publication Date
CN104899081A true CN104899081A (en) 2015-09-09
CN104899081B CN104899081B (en) 2018-03-09

Family

ID=54031759

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410082313.6A Expired - Fee Related CN104899081B (en) 2014-03-07 2014-03-07 The system and method for executable command outside a kind of calling based on JAVA technologies

Country Status (1)

Country Link
CN (1) CN104899081B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111078382A (en) * 2019-12-17 2020-04-28 中国建设银行股份有限公司 Command timeout processing method and device
CN112559070A (en) * 2020-12-09 2021-03-26 北京展心展力信息科技有限公司 Initialization method and device for starting application program, electronic equipment and medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050155044A1 (en) * 2004-01-12 2005-07-14 International Business Machines Corporation Communicating with remote objects in a data processing network

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050155044A1 (en) * 2004-01-12 2005-07-14 International Business Machines Corporation Communicating with remote objects in a data processing network

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
JACK-ZHU: "在Java中执行脚本命令以及调用外部程序说明", 《HTTP://BLOG.CSDN.NET/ZHU_XUN/ARTICLE/DETAILS/19539513》 *
失宠的女巫: "Java中使用Runtime和Process类运行外部程序", 《HTTP://BLOG.SINA.COM.CN/S/BLOG_4B2FD9350100QD3N.HTML》 *
魏鑫燏: "java调用需要输入的外部可执行程序", 《HTTP://BLOG.SINA.COM.CN/S/BLOG_7B83134B0101CW58.HTML》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111078382A (en) * 2019-12-17 2020-04-28 中国建设银行股份有限公司 Command timeout processing method and device
CN112559070A (en) * 2020-12-09 2021-03-26 北京展心展力信息科技有限公司 Initialization method and device for starting application program, electronic equipment and medium

Also Published As

Publication number Publication date
CN104899081B (en) 2018-03-09

Similar Documents

Publication Publication Date Title
CN107392611B (en) Method and device for sending transaction information and consensus verification
WO2019095580A1 (en) Test method and apparatus, computer device, and readable storage medium
CN103914322A (en) Terminal acceleration method and terminal
US20180052666A1 (en) Adaptive Recursive User Interface Testing Automation Framework
WO2020215686A1 (en) Spring framework generic dependency injection method and apparatus, computer device and storage medium
CN109033540B (en) Excitation management method and system in chip random verification process
US8751868B2 (en) Control server and method for switching running of test programs stored in multiple storage mediums of test server
CN106502770B (en) HMI state transition method based on finite state machine
CN109976723B (en) Algorithm development platform, algorithm development method and computer readable storage medium
WO2016036974A1 (en) Conditional wrapper for program object
CN106502773A (en) There is data asynchronous processing method and the module of synchronous callback information function
CN104899081A (en) System and method for calling external executable command on the basis of JAVA technology
CN104598340A (en) Detection system of hardware faults, electronic device and method
WO2019136837A1 (en) Intelligent load system, method and device, and storage medium
CN111443902A (en) Function call tree generation method, system, computer device and readable storage medium
CN106126260A (en) A kind of delayed data loading method and device
CN106708614B (en) multithreading creating system and method and multithreading processing system and method
CN106708566B (en) Method and system for judging whether application program is installed
CN111611008A (en) Software code packaging and deploying method, device, equipment and storage medium
CN112181388A (en) SDK component initialization method, device, storage medium and control terminal
CN116702668A (en) Regression testing method and device, electronic equipment and storage medium
CN105718556B (en) Database purchase and querying method, attribute value-acquiring method and equipment
CN113157324B (en) Starting method, device and equipment of computer equipment and readable storage medium
CN109656763B (en) Method and system for automatically testing and activating core function of source processor
CN105607991A (en) Test method and device based on asynchronous threads

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
PE01 Entry into force of the registration of the contract for pledge of patent right
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: A system and method of calling external executable command based on Java technology

Effective date of registration: 20210104

Granted publication date: 20180309

Pledgee: Inner Mongolia Huipu Energy Co.,Ltd.

Pledgor: WUXI TVMINING MEDIA SCIENCE & TECHNOLOGY Co.,Ltd.

Registration number: Y2020990001517

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20180309

Termination date: 20210307