Examples: Running an IBM PASE for i program from within IBM® i programs
These examples show an ILE program that calls an PASE for i program, and the PASE for i program that is called by the ILE program.
Note: By using the code examples, you agree to the terms
of the Code license and disclaimer information.
Example 1: An ILE program that calls an PASE for i program
The following ILE program calls an PASE for i program. Following this example is an example of the PASE for i code that this program calls.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
/* include file for QP2RunPase(). */
#include <qp2user.h>
/******************************************
Sample:
A simple ILE C program to invoke an PASE
for i program using QP2RunPase() and
passing one string parameter.
Example compilation:
CRTCMOD MODULE(MYLIB/SAMPLEILE) SRCFILE(MYLIB/QCSRC)
CRTPGM PGM(MYLIB/SAMPLEILE)
******************************************/
void main(int argc, char*argv[])
{
/* Path name of PASE program */
char *PasePath = "/home/samplePASE";
/* Return code from QP2RunPase() */
int rc;
/* The parameter to be passed to the
i5/OS PASE program */
char *PASE_parm = "My Parm";
/* Argument list for i5/OS PASE program,
which is a pointer to a list of pointers */
char **arg_list;
/* allocate the argument list */
arg_list =(char**)malloc(3 * sizeof(*arg_list));
/* set program name as first element. This is a UNIX convention */
arg_list[0] = PasePath;
/* set parameter as first element */
arg_list[1] = PASE_parm;
/* last element of argument list must always be null */
arg_list[2] = 0;
/* Call i5/OS PASE program. */
rc = Qp2RunPase(PasePath, /* Path name */
NULL, /* Symbol for calling to ILE, not used in this sample */
NULL, /* Symbol data for ILE call, not used here */
0, /* Symbol data length for ILE call, not used here */
819, /* ASCII CCSID for i5/OS PASE */
arg_list, /* Arguments for i5/OS PASE program */
NULL); /* Environment variable list, not used in this sample */
}
Example 2: The PASE for i program that is called in the ILE program
The following PASE for i program is called by the above ILE program.
#include <stdio.h>
/******************************************
Sample:
A simple PASE for i Program called from
ILE using QP2RunPase() and accepting
one string parameter.
The ILE sample program expects this to be
located at /home/samplePASE. Compile on
AIX, then ftp to IBM i.
To ftp use the commands:
> binary
> site namefmt 1
> put samplePASE /home/samplePASE
******************************************/
int main(int argc, char *argv[])
{
/* Print out a greeting and the parameter passed in. Note argv[0] is the program
name, so, argv[1] is the parameter */
printf("Hello from PASE for i program %s. Parameter value is \"%s\".\n", argv[0], argv[1]);
return 0;
}