RP Gpopen

Package Information
Summary Example RPG popen utility to call PASE utilities.
Maintainers Tony “Ranger” Cairns <adc@us.ibm.com>
License License
Download Download Latest ← click here
Description Example RPG popen utility to call PASE utilities for LUG and Common members interested in programming RPG with PASE utilities. RPG popen creates additional jobs via PASE fork, therefore if you SBMJOB you MUST allow more than 1 job in your batch queue (*NOMAX best). Download includes example RPG popen calls PASE curl for Yahoo stock quotes.
        rc = PaseStart32();
        PaseCurl = '/opt/freeware/bin/curl'
                 + ' -d s="'+%trim(cutESpace(symbols:*BLANKS:*OFF))
                 + '&f=snjkl1t8dr"'+
                 + ' http://download.finance.yahoo.com/d/quotes.csv';
        rc = PaseExec32(PaseCurl:%addr(OUT):%size(OUT):retLen);
        rc = PaseStop();
Common issues

Where are spool job log files??
I used WRKJOB option 4 to view spool files. One time I did a WRKSPLF and more appeared. That is how I found a PASE utility authorization (error). Makes sense because spinoff jobs process the PASE utility request (curl, php, etc.). I wasn’t seeing spools under current job, but did when I looked at all jobs.

I can’t call PHP with low authority profiles???
PHP ships without *PUBLIC access (except for SECOFR), here is how you fix.
call qp2term
> cd /usr/local
> chmod -R 0755 zendsvr      (or zendsvr6)

Example call PHP:

       rc = PaseStart32();
       PasePHP = '/usr/local/zendsvr/bin/php-cli'
               + ' /www/zendcore/htdocs/myscript'
               + ' type=title title=H num=3';
       rc = PaseExec32(PasePHP:%addr(OUT):%size(OUT):retLen);
       rc = PaseStop();

Similar tutorial RPG popen hacking RPG call PHP (partial tutorial).

CCSID issues (beyond English)

This sample uses QDCXLATE for function Translate for function PaseExec32 (reap shell output). You will need to replace this converter if you want CCSIDs for NLS (beyond English mostly). You can find MUCH better converter in wiki project LIBPASE (see libiconv_h.rpgle and libiconv.rpgle).

However, should be noted that PaseExec32 uses PASE fork/exec, thereby additional processes are created. This is completely normal for Unix scripting, but can introduce all manner of odd/bad behaviour dealing with CCSID. Most typically, when your machine has multiple languages installed, various profile and job settings can result in bad CCSID conversion. The answer is to move to something closer like wiki project LIBPASE, but this is much more difficult programming.

rpgpopen1.zip — clean RPG popen curl project only
rpgpopen.zip — contains files not part of popen curl project