You can run an application from within a CL program that transfers control to your program using the Transfer Control (TFRCTL) command. This command:
In the following example, the TFRCTL command in a CL program RUNCP calls a C++ program XRUN2, which is specified on the TFRCTL command. RUNCP transfers control to XRUN2. The transferring program RUNCP is removed from the call stack.
Figure 28 illustrates the call to the CL program RUNCP, and the transfer of control to the C++ program XRUN2.
Figure 28. Calling Program XRUN2 Using the TFRCTL Command
![]() |
To create and run programs RUNCP and XRUN2, follow the steps below:
CRTCLPGM PGM(MYLIB/RUNCP) SRCFILE(MYLIB/QCLSRC)
CRTBNDCPP PGM(MYLIB/XRUN2) SRCSTMF(xrun2.cpp)
CALL PGM(MYLIB/RUNCP) PARM('nails')
The output from program XRUN2 is:
+--------------------------------------------------------------------------------+ | string = nails | | Press ENTER to end terminal session. | | | +--------------------------------------------------------------------------------+
Figure 29. Example of Source Code that Transfers Control to Another Program
|
Figure 30. Example of Source Code that Receives and Prints a Null-Terminated Character String
// xrun2.cpp // Source for Program XRUN2 // Receives and prints a null-terminated character string #include <iostream.h> int main(int argc, char *argv[]) { int i; char * string; string = argv[1]; cout << "string = " << string << endl; } |
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.