Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.33 Sample 32: Starting Another Program

Sample 32 demonstrates a program that starts another program, waits for the started program to terminate, and receives a completion code from the started program via inter-program communications.

Overview

When SAMPLE32 is executed, you are prompted for a program to run. If you enter nothing, the program MSGBOX.EXE from the SAMPLE31 folder is executed. If you specify a program name, you must enter the fully qualified path to the location of the application (or batch file) to execute.

The Windows system function “CreateProcessA” is called specifying this for the argument, and specified program or batch file is started.

If the specified program is successfully started, SAMPLE32 then waits until the specified program terminates and then receives the completion code from the started program.

Files Included in Sample 32

COBOL Statements Used

Before Executing the Application

SAMPLE32 uses MSGBOX.EXE from SAMPLE 31. Therefore, please build the MSGBOX application prior to executing SAMPLE32.

In the following screens, SAMPLE06 is also executed, therefore please build SAMPLE06 prior to executing SAMPLE32.

Building and Rebuilding

The Project Manager's build function is used to compile and link this program.

In the screen snapshots below, NetCOBOL was installed in folder C:\NetCOBOL.

Change the folder name C:\NetCOBOL to the name of the folder where NetCOBOL is installed on your machine.

  1. Start the Project Manager.

  2. Open the project file SAMPLE32.PRJ.

  3. Select "Build" from the "Project" menu.

    After build termination, check that SAMPLE32.EXE is created.

Executing the Program

  1. Select "Execute" on the "Project" menu.

    The following display appears and waits for your input.

  2. Input the path and filename of an executable program or batch file. The environment variable PATH is not referenced here, therefore it is necessary to specify a relative path from the SAMPLE32 folder, or a fully qualified path name.

    If nothing is entered, then MSGBOX.EXE of SAMPLE31 is executed. Press the ENTER key.

  3. The completion code of MSGBOX.EXE of SAMPLE31 is displayed (indicating what button was pushed). In the following screen, the “No” button was pressed.

  4. If SAMPLE32 is reexecuted and an executable program or batch file name is specified, you are then prompted to enter command line arguments (if any) for the EXE or BAT file, as shown below.

  5. SAMPLE06.EXE requires two command line arguments. Please note that the command line arguments are specified following the program name.

  6. A message indicating that SAMPLE06 has been started is displayed. (The system console is opened and the execution result of SAMPLE06 is output.) The completion code of SAMPLE06.EXE is displayed and execution ends.