Opening a Browser an Interactive 5250 Session

Bad Joke of the Month

IT Help Desk:  Hello sir, what seems to be the problem?
User: My computer won’t turn off and back on again.
IT Help Desk:  Oh no!  I don’t know what to do!

Opening a Browser in an Interactive 5250 Session

Since 5250 displays are still the most common user interface for users, and since there are many powerful features available on the web, it is extremely commonplace to want to open a web browser from green screen. While there are many ways to do this, they don’t all work equally well; experience has shown that certain approaches work much better than others.  I will share my experience in this post.

The Simplest Approach

The simplest approach is to use the STRPCCMD tool in conjunction with the Windows FileProtocolHandler.  The biggest disadvantage to this approach is that it will only work for users who use Windows as their desktop.

PGM PARM(&URL)


 DCL VAR(&URL) TYPE(*CHAR) LEN(975)

 DCL VAR(&CMD) TYPE(*CHAR) LEN(1000)


 STRPCO

 MONMSG MSGID(IWS4010)


 CHGVAR VAR(&CMD) +

   VALUE(‘rundll32 url,FileProtocolHandler’ *BCAT &URL)


 STRPCCMD PCCMD(&CMD) PAUSE(*NO)


ENDPGM

Since this has a large parameter, you will have trouble calling it directly from the command line.  Instead, I recommend using a simple command interface:

CMD PROMPT(‘Open a URL’) ALLOW(*INTERACT *IPGM)

PARM KWD(URL) TYPE(*CHAR) LEN(995) CASE(*MIXED) +
PROMPT(‘URL to open’)

You can compile it like this:

CRTBNDCL PGM(QGPL/OPENURL) srcfile(YOUR-LIB/QCLSRC)
CRTCMD CMD(QGPL/OPENURL) PGM(QGPL/OPENURL)

And run it like this:

OPENURL URL(‘https://www.youtube.com/watch?v=ylKD9c837gM’)

Don’t Use the ‘start’ Utility!

In my experience the most common problem people have this approach (aside from the fact that it only works on Windows) is that instead of using the FileProtocolHandler shown above, they use the Windows ‘start’ utility.

While ‘start’ can work in many circumstances, it has two big problems:

  • It opens a Command Prompt (DOS prompt) to run the command, and the user sees the ugly black window open, often causing confusion.
  • Because it runs as a DOS command, many of the characters commonly used in URLs have a special meaning, and so can’t be used in a URL.

Frustratingly, there are a lot of places on the Internet that show examples of using the ‘start’ utility.  My experience is that FileProtocolHandler is a much better option.

What About Mac Users?

While there are shops that are happy with only supporting Windows desktops, in other shops it is not practical because so many users run MacOS.  Since MacOS doesn’t have a rundll32 utility, or a FileProtocolHandler routine, you need to change the program.

PGM PARM(&URL)

  DCL VAR(&URL) TYPE(*CHAR) LEN(975)
  DCL VAR(&CMD) TYPE(*CHAR) LEN(1000)

  STRPCO
  MONMSG MSGID(IWS4010)

  CHGVAR VAR(&CMD) +
         VALUE(‘open’ *BCAT &URL)

  STRPCCMD PCCMD(&CMD) PAUSE(*NO)

ENDPGM

 

Compile this using the same CRTBNDCL and CRTCMD commands as above (the command source doesn’t need to change.)

This will work to launch a URL on MacOS since it’s ‘open’ utility will open a URL with the user’s preferred default browser, which works nicely on Mac.  But now that I’ve changed the code, it no longer works on Windows!

If there was some way to detect which OS the user is running, you could simply use the correct command for whatever environment it is – but, I am not aware of any good way to do that.

How About an Open Utility for Windows?

My solution to this dilemma is to create an open utility that runs on Windows. I instruct the people who set up new PCs to always install this utility and to put it in all of the users PATH variables. Since the name of the tool is ‘open’, just like the command found on MacOS, I can issue the same command (as shown in the Mac section, above) regardless of what type of computer they are using.

You can get the ‘open’ utility for Windows (it is open source and completely free) from my web site here: https://www.scottklement.com/open/

To install it:

  • Create a folder C:\UTILITIES on the PC
  • copy the .EXE file from the above URL to the new folder
  • click the Start Menu and search for “environment variables
  • click the environment variables button, and edit the Path variable (under “system”) and add the C:\UTILITIES folder to the list of folders in the Path
  • Reboot the PC

Now the same approach works on both Windows and Mac, so I can open up a URL in a browser regardless of which the end user prefers to use.

Scott Klement

Development and Solutions Architect 
Scott Klement is an IT professional with a passion for both programming and mentoring. He joined Midrange Dynamics at the beginning of October 2022. He formerly was the Director of Product Development and Support at Profound Logic and the IT Manager and Senior Programmer at Klement’s Sausage Co., Inc. Scott also serves on the Board of Directors of COMMON, where he represents the Education, Innovation, and Certification teams. He is an IBM Champion for Power Systems. 

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *