Article copyright by the author Xiaohui Li is and the blog park, if reproduced please clearly indicate the source: http://www.cnblogs.com/naaoveGIS/
1. Background
In a project, it is necessary to consider using Java background to invoke the transduction program (EXE) written by C #, and the front-end to obtain progress and related descriptive information for transduction.
2. Solution Ideas
A. First, the transformation of the diagram program for accepting parameters from the main function is passed.
B. A function that writes the java background parameter call EXE.
C. Address communication issues.
3. Implementation 3.1 Rewrite C # form program
The entry program in C # is the main function, where the main function defaults to no parameters, and if you add a parameter, it supports only one string array parameter, and the entry is rewritten as follows:
The parameters that need to be passed in are written in the args array, and the subsequent business logic is then rewritten accordingly.
3.2java End-Pass Call
The process class can be used in Java to invoke an EXE or a named line cmd. Specific examples are as follows:
Where exec is a call to a parameter, and the WAITFOR function waits for the function for the current thread, and can get the value returned after the process that is represented by that process object terminates.
If the return parameter is not set in the EXE, the default execution is 0 correctly.
3.3 Communication Design 3.3.1 Programme I
A. The front-end makes a request and waits for a response.
B. The background accepts the request and invokes the EXE.
C.exe writes the information to the specified text when it finishes executing.
After the D.java-end listener finishes executing, gets the specified text.
E. Parsing the information in the text. Information can be organized in accordance with custom rules to convey the meaning of the desired representation.
F. Return the parsed data to the front end.
Advantages:
The front end does not require polling and waits for the result to be returned.
Disadvantages:
A request time-out issue occurs, and the current state of EXE execution cannot be known.
3.3.2 Program II
A. The front-end makes the request and starts to trigger the program status query request periodically.
B. The background accepts the request and invokes the EXE.
C.exe writes the information to the specified text after the execution of the procedure.
D. A front-end status query request that continuously reads state information from the specified text and displays it in the front end.
Advantages:
Circumvent the request timeout problem, you can get the program process in real time.
Disadvantages:
The front end requires a timed status polling request.
-----Welcome reprint, but retain the copyright, please indicate the source in obvious place: http://www.cnblogs.com/naaoveGIS/
One way to invoke EXE using Java parameters and get program progress and return results