|
Running a Post-Script from GPP2
Often, it is required to copy, move or rename the files generated in the posting process, in order to complete the job. Sometimes, several files should be merged to one file, and so on.
With GPP2, it is possible to execute such file manipulation system commands from inside the EX2 program, without the need to execute a separate script (batch) file.
A block, POST SCRIPT, was added in GPP2. It is executed after all other blocks have been executed (including END OF FILE) and after GPP2 closes all the output files.
In the block, it is possible to use a special command, SYSTEM_CALL, which causes the execution of any system command, such as copy or rename. The SYSTEM_CALL is similar to the OUTPUT command in its format. It allows combining strings and variable names to form any system command affecting the files associated with this specific run.
Note that some commands are not allowed in the POST SCRIPT block, since they attempt to write to the output files which are already closed. The following commands are not allowed:
-
OUTPUT, PRINT, PRINT1, etc.
-
OUTPUT_REDIRECT and OUTPUT_BACK
-
GPP_CALLPROC (since the procedure may contain output commands)
Other GPP2 commands can be freely used, including IF and other program control statements.
One advantage of using SYSTEM_CALL instead of running an external batch file is debugging. By using step-by-step debugging, it is possible to pause and check the results of each individual command.
The POST SCRIPT block is also invoked in the case of runtime errors and in case the run was stopped using the GPP_STOP command. In such a case, it is invoked with the stopped: qualifier, allowing the EX2 program to clean up after the non-successful run (typically, delete all the files that were created during the run).
Unlike most blocks, the stopped POST SCRIPT block does not fall back to the regular block (with no qualifier). In cases of failure, GPP2 will only execute the POST SCRIPT block with the explicit stopped: qualifier.
More detail on the use of SYSTEM_CALL is given in the GPP2 Language Reference Manual.
|