|Title: In thin client mode how do I run a local external application like the Windows Calculator or Microsoft Excel?|
|There are several ways that an application running on a server can launch an application on the client. The three most common are:
1. CALL CLIENT "SYSTEM", "C$RUN" or "C$SYSTEM"
2. CALL CLIENT "ShellExecuteA" ...
3. CALL CLIENT "MYPROG" (where MYPROG is a COBOL program)
1. CALL CLIENT "SYSTEM", "C$RUN" or "C$SYSTEM" The SYSTEM, C$RUN and C$SYSTEM library routines allow a program to run an operating system command line as if it was executed from a command prompt, shell, script, batch file, or shortcut. SYSTEM runs the command synchronously so that the program waits for the command to complete before continuing. C$RUN runs the command asynchronously so that the program continues to run in parallel with the command. C$SYSTEM combines the functionality of SYSTEM and C$RUN and allows a command to be run synchronously or asynchronously depending on a "flags" parameter. Add the CLIENT clause to the CALL statement in order to run the command on the client-side. The isCOBOL framework ignores the CLIENT clause when not running in thin client mode. So CALL CLIENT is safe to use in programs that run in both thin client and local modes. For example, to launch the Windows calculator program: CALL CLIENT "C$RUN" USING "calc". If Microsoft Excel is in the client-side PATH then you could launch it with: CALL CLIENT "C$RUN" USING "excel.exe". However, usually excel.exe is not in the PATH. So you would need to specify a full path such as in:
CALL CLIENT "C$RUN" USING "C:Program FilesMicrosoft OfficeOFFICE11excel.exe".In order to identify whether excel.exe is installed and its disk location you could read the registry using CALL CLIENT with the registry library routines such as REG_OPEN_KEY and REG_QUERY_VALUE. But a better way is to call the Windows ShellExecute API function instead. Continue reading. 2. CALL CLIENT "ShellExecuteA" ... The Windows API ShellExecute function opens or prints a specified file. This function is located in shell32.dll. You can use the ShellExecute function to start an application assocated with a given document extension without knowing the name of the associated application. For example, you could start the Paintbrush program by passing the filename ARCADE.BMP to the ShellExecute function. For example, the following program will open file.csv with whatever application is associated with the .csv file extension. If Microsoft Excel is installed on the system then it is most likely the application that will launch:
ID DIVISION. PROGRAM-ID. LAUNCHCSV. DATA DIVISION. WORKING-STORAGE SECTION. 78 SW-SHOWNORMAL VALUE 1. 77 RETURN-VAL USAGE LONG. PROCEDURE DIVISION. MAIN-LOGIC. * SEE http://support.microsoft.com/kb/238245 CALL CLIENT "C$SETENV" USING "dll_convention", "1". CALL CLIENT "shell32.dll". CALL CLIENT "ShellExecuteA" USING BY VALUE 0, BY REFERENCE "open", BY REFERENCE "file.csv", BY REFERENCE "", BY REFERENCE "", BY VALUE SW-SHOWNORMAL RETURNING RETURN-VAL. IF RETURN-VAL < 32 THEN DISPLAY "ERROR: ShellExecute() returned ", RETURN-VAL END-IF. STOP RUN.See http://support.microsoft.com/kb/238245 and http://support.microsoft.com/kb/170918 or search for ShellExecute at http://msdn.microsoft.com for more information. 3. CALL CLIENT "MYPROG" (where MYPROG is a COBOL program) If a program named MYPROG is available in the client-side class path, then a program running on the server can call it using CALL CLIENT "MYPROG" and can pass it input, output or input-output parameters of any type by reference or by value just as if it was calling the program on the server. For example, you could compile the following program and add it to your client-side jar file or have your installer put it on the client in the class path specified when your users launch the thin client:
ID DIVISION. PROGRAM-ID. MYCALC. PROCEDURE DIVISION. CALL "C$RUN" USING "calc".You could call this program from your application with: CALL CLIENT "MYCALC". Note that there are differences in behavior of C$RUN/C$SYSTEM between isCOBOL and ACUCOBOL-GT. For example, calls relying on UNIX/Linux shell syntax for redirection of standard streams should be made using the SYSTEM routine. See http://www.veryant.com/support/phpkb/question.php?ID=113 for more information and workarounds for C$RUN/C$SYSTEM if you need platform specific functionality.
|Authored by: Veryant Support on Thu, Nov 5th, 2009 at 7:00 PM
This question has been viewed 26913 times so far.
|Online URL: http://support.veryant.com/support/phpkb/question.php?ID=110|
Powered by PHPKB Knowledge Base Software