ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

STRPCCMD and Ampersands

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • STRPCCMD and Ampersands

    I am trying to start a URL from a green screen session using the STRPCCMD. First off the URL will exceed the 123 character limit for STRPCCMD in version 7.1. I am having to split the URL and run the command using a .bat file. My issue is that the command is having issues with the ampersands in the URL that are used to pass parameters. Here is my code:
    Code:
    CHGVAR     VAR(&URL) +                                   
                 VALUE('HTTP://hostname:8080/profoundui/start?pgm=TESTICSUI/SY0960+
                 &p1=' +    
                 *CAT &FTPKEY *TCAT +                        
                 '&l1=30&workstn=ICSUI0326&suffixid=1')      
    
    CHGVAR     VAR(&URL_1) VALUE(%SUBSTRING(&URL 1 60))      
    CHGVAR     VAR(&URL_2) VALUE(%SUBSTRING(&URL 61 120))    
    CHGVAR     VAR(&FIRST) VALUE('CMD /C ECHO SET' *BCAT +   
                 '"' *CAT 'FIRST=' *TCAT &URL_1 *TCAT +      
                 '"' *BCAT '> C:\TEMP\URL.BAT')              
    CHGVAR     VAR(&LAST) VALUE('CMD /C ECHO SET' *BCAT +    
                 '"' *CAT 'LAST=' *TCAT &URL_2 *TCAT +       
                 '"' *BCAT '>> C:\TEMP\URL.BAT')             
    
    STRPCO     PCTA(*NO)                                     
    MONMSG     MSGID(IWS4010)                                
    
    STRPCCMD   PCCMD('DEL C:\TEMP\URL.BAT')                  
    STRPCCMD   PCCMD(&FIRST)                                 
    STRPCCMD   PCCMD(&LAST)                                  
    STRPCCMD   PCCMD('CMD /C ECHO SET RESULT=%FIRST%%LAST% + 
                 >> C:\TEMP\URL.BAT')                        
    STRPCCMD   PCCMD('CMD /C ECHO Start iexplore.exe +
                              %RESULT% >> C:\TEMP\URL.BAT')                       
    STRPCCMD   PCCMD('START C:\TEMP\URL.BAT') PAUSE(*NO)
    The error occurs at the "SET RESULT" of the split URL (see attached image). I can do this with another URL if it has no ampersands but the ampersands are required here. Any suggestions? Thanks!

  • #2
    Eric,

    You use our product -- a web-based display. Why on earth would use use STRPCCMD to open a URL in a browser?!

    Instead, put the URL into s hidden variable bound to a display. Then use the JavaScript window.open() routine to open a new browser window. No worries about escaping special characters, and the length limit is around 32000, which is more than you need. Plus, it's both more efficient and secure than a PC command.

    But, if you must do this from green screen, don't use "start iexplore.exe". (a) you are forcing a DOS window by using "start", and (b) you are forcing Microsoft Internet Explorer instead of whichever browser the user configured his/her PC to use. IE currently is about 8% of the browser market share (the lowest of any major browser) and even it's author, Microsoft, doesn't want people to keep using it. Why would you want to hard-code it into an application?

    Instead, use the Windows FileProtocolHandler like this:

    Code:
    PGM  PARM(&URL)
    
         DCL VAR(&CMD) TYPE(*CHAR) LEN(123)
         DCL VAR(&URL) TYPE(*CHAR) LEN(90)
    
         STRPCO PCTA(*NO)
         MONMSG IWS4010
    
         CHGVAR VAR(&CMD) +
         VALUE('rundll32 url,FileProtocolHandler ' *BCAT &URL)
    
         STRPCCMD PCCMD(&CMD) PAUSE(*NO)
    
    ENDPGM
    If you must make a batch file, that makes things much more complicated because you're running DOS and therefore you have to escape characters like the & character. This is possible, but complicated because you have to escape them multiple times... once for the "echo" command and again for the bsatch file, amd again for each set command that's used to combine multiple variables... so things have to be escaped multiple times.... really, really, ugly.

    A better way would be to use as CGI program to do redirects as demonstrated here:
    Read through for news and resources on software development topics, including low-code-no-code, serverless computing and programming languages.


    If you must escape them and build a bsatch file, it is possible, but... well, I'll wait until you say "I absolutely must do that" because it is the worst way, and I'd rather not explain it if you're willing to do it a better way.

    Comment


    • #3
      Hey Scott!! Happy late Thanksgiving!!!!

      This does HAVE to come from a green screen. Just how this is set up and how I was told to do it. After posting this I did remove the iexplore.exe to get it to use the default browser, so that is working. I was following an example I found online since this is my first use of the STRPCCMD.

      I do have to use a .bat file due to the anonymous URL being over the 123 character limit for STRPCCMD. Have to split it up into sections. We are still at version 7.1 so still have that limitation. I also think I found that using the ^ character will pass the ampersand through correctly but have not been able to test that thoroughly (found it right before I left work Wednesday evening).

      When I get back into the office on Monday, I will check out the redirects and see if that will help me out.

      Appreciate the reply!!!!!

      Comment


      • #4
        Scott, I have a simple program like this, but it uses START and then the URL instead of rundll32, etc. the way you show above. Pros and cons of each? Thanks.

        Comment


        • #5
          Scott,

          An update on this. What we are doing here is from the WRKMBRPDM screen we have some user defined functions to copy source/objects to an FTP library and then using RPGSp programs, we display a browser screen to select which of our remote clients we want to send the saved source/objects to. We have replaced all our RPGSp programs with PUI except this one. The powers that be want to keep it this way, so that is why I am forced to do this from the green screen.

          I did use the "^" as escape characters for the ampersands and it is working correctly. We use a generic anonymous program (which is a CL) so we don't have to keep adding the programs AND it does some library/security manipulation.

          That being said the .bat file looks like it is building just like it should. I have attached another photo of what I get when running the STRPCCMDs. And that is gray area since this goes back to an issue with the URL and the PUI anonymous programs, I believe. (Don't know if I should discuss this here on the PUI forum or both). When the final START from the .bat file is executed, I can see the full URL flash in the browser address bar but it immediately disappears and is replaced with the default URL to start a regular PUI session. I do have a button on a regular PUI screen to start to call this anonymous program from an onclick event and it works great. It just does not like the built URL from the STRPCCMD on the green screen.

          Thanks for any assistance on this. My first jump into this side of things on the green screen and am scratching my head.

          Click image for larger version

Name:	STRPCCMD 02.JPG
Views:	0
Size:	79.3 KB
ID:	146983

          Comment


          • #6
            Update on this. I got it working. Besides having to place the "^" character before each "&" I also had to place %%20 for any blank character. If I used just %20 for the blank, DOS would strip out the %2 and leave the just the zero. Bottom line is that now this is working as we need it. Thanks to all who helped in this. It certainly was a learning experience!!!!

            Comment

            Working...
            X