support: Customer Portal
Focused on delivering choice, investment protection and flexibility to organizations with valuable COBOL assets
 

Veryant Knowledge Base
Home > All Categories > isCOBOL Server and Thin Client > In thin client mode how do I run a local external application like the Windows Calculator or Microsoft Excel?
Question 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 Files\Microsoft Office\OFFICE11\excel.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 This question has been viewed 11742 times so far.
Click Here to View all the questions in isCOBOL Server and Thin Client category.
File Attachments File Attachments
There are no attachment file(s) related to this question.
How helpful was this article to you?
User Comments User Comments Add Comment
There are no user comments for this question. Be the first to post a comment. Click Here
Related Questions Related Questions
  1. How do I set up isCOBOL Server (Application Server) and Thin Client?
  2. How do I debug a program running in thin client mode?
  3. How do I use Java Web Start to automatically download and launch the thin client?
  4. How do I capture client side errors when using a different look and feel (e.g. Nimbus)?
  5. With thin client is there a way to update and push changes to programs live (on the fly), without having to kill and restart the isCOBOL Server?
  6. How do I avoid having to edit the Java security policy to allow isCOBOL thin client applet to connect?
  7. How do I use secure transport (SSL) with the isCOBOL thin client?
  8. How do I download files from server to client using isCOBOL Thin Client?
  9. The COBOL program suddenly terminates on the server and leaves thin client running with a blank screen
  10. How can I get the system-information data from the client computer?
  11. What are the Java version requirements on the client and server? Do they need to match?
  12. How do I resolve the error 'Application Blocked by Java Security' working with jnlp?
  13. Is there a way to simulate users and load-test the thin client?
  14. The user name shown by the -panel is the PC Name. Is it possible have the user id of our application?
  15. How can I get the local username?
  16. Is there a way to distribute multiple client connections on different servers?
Article Information Additional Information
Article Number: 110
Created: 2009-11-05 3:55 PM
Rating: 1 Star
 
Article Options Article Options
Print Question Print this Question
Email Question Email Question to Friend
Export to Adobe PDF Export to PDF File
Export to MS Word Export to MS Word
Bookmark Article
Subscribe to Article Subscribe to Article
 
Search Knowledge Base Search Knowledge Base



 
 

© Veryant - All Rights Reserved
Veryant and isCOBOL are trademarks or registered marks of Veryant in the United States and other countries. All other marks are the property of their respective owners.