TechTalk: Command Processor Quirk?

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Command Processor Quirk?

The other day, while I was creating a new utility command to use with PC Support, I came across a strange quirk of the command processor. I defined a parameter as type *CHAR, 64 characters long, so it would accept a complete PC path, including the file name with its extension.

It turns out, however, that the backslash character () is considered an invalid character, unless you enclose the path in single quotes. This means that I could not type SUBDIRFILENAME.EXT in the parameter, but had to enclose it in single quotes. That's not all, though. The worst part is how the command processor treats an unquoted colon character (:).

First, I wanted to specify A: in the path parameter, so I typed in an A and a colon. I kept getting "Invalid directory" messages from DOS and, since DOS doesn't give much detail in its error messages, I was stumped until I started debugging and threw in a breakpoint. The command processor had removed the colon. Further testing revealed the following:

o If you type a colon at the end of an unquoted string, the command processor removes the colon.

o If you type a colon at the end of a quoted string, the command processor preserves the colon.

o If you prompt for the command and type an unquoted string that has an embedded blank and ends in a colon, the colon is preserved because in this case the command prompter supplies the quotes, turning the string into a quoted string.

If the above steps are repeated using a parameter of type *CMDSTR (command string), the results are different:

o Ending colons are always preserved.

o If you type an embedded colon, the portion of the command string prior to the colon is assumed to be a label (as in a CL program) and the portion after the colon is assumed to be a valid command name. If the command doesn't exist, you get an error message.

o If you embed two or more colons, you get an error message because there's more than one label in the command.

o Backslash characters are invalid in command parameters, in the portion before the first blank (which is assumed to be the command name) and in unquoted command parameters.

I can understand about the backslashes being invalid characters, but why isn't the colon treated the same way? It took me a while to find the source of the problem, and I can find no circumvention. To this day, I have to make sure I enclose in quotes the PC path in my custom PC Support commands. I've included a simple command and its processing program (Figures 1 and 2) for you to try out this quirk.


TechTalk: Command Processor Quirk?

Figure 1 Command #EM002

 /* */ /* To compile: */ /* */ /* CRTCMD CMD(XXX/#EM002) PGM(XXX/#EM002CL) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ #EM002: CMD PROMPT('Test Command') PARM KWD(CHAR) TYPE(*CHAR) LEN(32) + PROMPT('Character') PARM KWD(CMD) TYPE(*CMDSTR) LEN(32) + PROMPT('Command') 
TechTalk: Command Processor Quirk?

Figure 2 CL Program #EM002CL

 /* */ /* To Compile: */ /* */ /* CRTCLPGM PGM(XXX/#EM002CL) SRCFILE(XXX/QCLSRC) */ /* */ #EM002CL: PGM PARM(&CHAR &CMD) DCL VAR(&CHAR) TYPE(*CHAR) LEN(32) DCL VAR(&CMD) TYPE(*CHAR) LEN(32) SNDPGMMSG MSG('Char =' *BCAT &CHAR) MSGTYPE(*INFO) SNDPGMMSG MSG('Cmd =' *BCAT &CMD) MSGTYPE(*INFO) ENDPGM 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: