Executing PHP script from CL using qp2shell and php-cli

785 pts.
Tags:
CL
IFS
PHP
I have a PHP script on the IFS which I need to call from a CL program using qp2shell and php-cli. I have the following code which works:
CALL  QP2SHELL  PARM('/usr/local/zendsvr6/bin/php-cli' '/stuff/phpEmailer/index.php')
However, I need the path to the PHP script ('/stuff/phpEmailer/index.php') to be passed as a variable for the qp2shell parameter since this can change. This is where I'm having problems. If I declare a variable and assign the same path to it the call doesn't work. I get the following error when the CL program is run:
PASE for i program not found or in use. Path name is
'/usr/local/zendsvr6/bin/php-cli' '/stuff/phpEmailer/index.php'

Error loading PASE for i program '/usr/local/zendsvr6/bin/php-cli'
'/stuff/phpEmailer/index.php'
Can someone please help me? I can't understand why it works when the path is explicitly defined as opposed to when its passed as a variable.

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 8  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • jailall101
    I found what the issue is. 
    Apparently 2 spaces are in front of the variable value when the call is made using variable as a parameter.. 
    So instead of '/stuff' the value is actually '  /stuff'
    This causes a problem because it detects the space ' ' as the second parameter.
    I am still unable to resolve this issue because no matter what i try to do in the CL i cant seem to get the spaces out %TRIM does not work for some reason. I used %TRIM(path) before the call is made but still i dont kno where the spaces are coming from.
    785 pointsBadges:
    report
  • Splat
    Maybe I've missed something, but I didn't think %trim() was an option in CL.

    If you're doing your string manipulation in CL, try *TCAT.
    12,600 pointsBadges:
    report
  • jailall101
    Yes %trim is allowed in CL. I also tried *TCAT but that didn't work either. I can't get the spaces out. And I can find a replace function in CL to replace the spaces.
    785 pointsBadges:
    report
  • GregManzo
    Try including the quotes _inside_ the variable:
    var = '/stuff...' & PARM('etc/bin/php-cli'  %trim(var) )
    rather than:
    var = /stuff... & PARM('etc/bin/php-cli'  '%trim(var)' )
    2,785 pointsBadges:
    report
  • Splat
    Would you post your code?
    12,600 pointsBadges:
    report
  • jailall101
    Actually the variable value is being returned by a program call. However i trimmed the return value and verified that it is not being returned with spaces at the beginning. Here's my code:

                 PGM

                 DCL        VAR(&SCRIPT) TYPE(*CHAR) LEN(500) VALUE(' ')             
                 DCL        VAR(&PHPCMD) TYPE(*CHAR) LEN(100) VALUE('/usr/local/zendsvr6/bin/php-cli')
     
               /*Null character*/
                 DCL        VAR(&NULL) TYPE(*CHAR) LEN(1) VALUE(X'00')
     
               /*Represents a single quote */
                 DCL        VAR(&Q)   TYPE(*CHAR) LEN(4) VALUE('''')
                 
     
     
                            /*call program to get and return the php script path*/
    /*This is where the issue is. The variable was trimmed and */
    /*verified that there were no spaces when the program returned the value*/
    /*But still at this point &SCRIPT has 2 spaces at the beginning of the string*/
                 CALL       PGM(PGM004R01)  PARM(&SCRIPT)
                 
                /*Attempt to trim the variable to remove the spaces but does not work*/
                 CHGVAR     VAR(&SCRIPT) VALUE(%TRIM(&SCRIPT))
     
                            /*Null terminate the string*/
                 CHGVAR     VAR(&PHPCMD) VALUE(&PHPCMD *TCAT &NULL)
                                          
                            /*Insert quotes at the beginning and end of the php path string */  
                 CHGVAR     VAR(&SCRIPT) VALUE(&Q *tcat %trim(&SCRIPT) *CAT &Q)
                                           
       /*call QP2SHELL and pass the parameters   
                 CALL       PGM(qp2shell) PARM(&PHPCMD &SCRIPT)           

                 endpgm

    785 pointsBadges:
    report
  • GregManzo
    If %trim() isn't removing the spaces then I'd suggest they probably _aren't_ spaces but some other non-printable character, possibly even 2 length bytes. How is the parameter defined in PGM004R01 ?
    If it's a VarLen field then that's your problem. You need to have the parameter defined the same in both PGM004R01 and this calling CL.
    2,785 pointsBadges:
    report
  • Splat
    I would also suggest you put PGM004R01 in debug & take a look at the value it's returning to your CL before it closes.
    12,600 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: