The Natural user exit
SHCMD can be used to issue an
operating system command, call a shell
script or execute an
executable program on UNIX from within a Natural program.
This document covers the following topics:
Command to be executed under control of the operating system command shell. Natural waits until the command is completed and then Natural returns control back to the Natural program.
For more information, see Examples below.
See Parameter Options below.
The following parameter options are available:
||This option is used to hide the output generated by the command. The hidden output is redirected to the null device.|
||This option is used to refresh the Natural screen output after the command is completed.|
NOSCREENIO may be not set at the same time.
The following return code values are available:
||Command successfully executed.|
||Illegal SHCMD parameter specified.|
|All other codes||Command shell return code.|
Execute a command shell from within Natural:
CALL 'SHCMD' 'myshell.sh'
Execute an executable program from within Natural:
CALL 'SHCMD' 'myprogram'
Execute the operating system command
ls on UNIX to list the contents of a directory:
CALL 'SHCMD' 'ls'
After executing the
ls command, you will
recognize that the output generated by this command has changed the last
Natural screen output. You have to press the refresh-screen key to clear the
screen. To do this automatically, you can specify the
CALL 'SHCMD' 'ls' 'SCREENIO'
Retrieve the return code by using the
DEFINE DATA LOCAL 1 rc (I4) END-DEFINE CALL 'SHCMD' 'lsDIRECTORY' 'SCREENIO' ASSIGN rc = RET( 'SHCMD' ) /* retrieve return code IF rc <> 0 THEN IF rc = 4 THEN WRITE NOTITLE 'Illegal option specified' ELSE WRITE NOTITLE 'Command not executed successfully (rc=' rc ')' END-IF ELSE WRITE NOTITLE 'Command executed successfully' END-IF END