Monday, January 29, 2007

REXX & System Commands

Chapter 6 of Down To Earth REXX, by Bill Schindler, discusses executing system (OS/2 in this case) commands from your REXX scripts. Essentially, REXX passes anything it does not understand to the operating system's command interpreter. However, it is possible to confuse the REXX interpreter or to have it send the command in a manner that confuses the shell (command.exe, cmd.exe, bash, sh, csh, or whatever). In order to prevent this, he recommends that all commands be enclosed in quotation marks, either "double quotes" or 'single quotes'.

This is a good book, even if it is focused on OS/2. I would recommend its purchase. I do not have an Amazon store, so I don't get any money off of it, but the book is solid.

In chapter 6, there are a few ways to access system information:

  • DIRECTORY(): returns the current working directory; to change directories, use DIRECTORY('dirname'), where dirname is the name of the desired directory.
  • SETLOCAL: saves the current directory and some environment settings. I thought it was an OS/2-only thing, but it works (sometimes) in Linux also.
  • ENDLOCAL: returns to the latest values saved by SETLOCAL.

I was struggling with one REXX script, where I kept trying to get it to use a data file in a separate directory. 'cd ./data' would not work reliably. Now I know why: there is a way built into REXX to do this.

One thing that you probably do not want to do (in real life, as opposed to teaching yourself how to use REXX) is use REXX to convert existing batch files & shell scripts, unless you are adding some functionality to them. Unix / Linux shell scripts, for example, have a great number of tools that they can access directly, where REXX would be likely to call the shell to execute the same tool and possibly require a work-around to get the results back into your script. Batch files (DOS, OS/2, or Windows), on the other hand, are much less powerful. REXX may indeed be a viable tool to replace some batch files, although it might be better to use KiXtart for this. KiXtart documentation is available from ScriptLogic.

Stay tuned. There is more to come... :-)

technorati tags:, , ,

Blogged with Flock

0 comments:

Post a Comment

All comments are moderated. Your comment will show up after approval.