The Natural user exit SHCMD
can be used to issue an operating system
command, call a shell script or execute an
executable program on Linux from within a Natural
program.
This document covers the following topics:
CALL 'SHCMD' 'command' ['option']
|
command
|
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. |
option
|
See Parameter Options below. |
The following parameter options are available:
Note:
The options SCREENIO
and NOSCREENIO
may be not
set at the same time.
The following return code values are available:
Return Code | Description |
---|---|
0 |
Command successfully executed. |
4 |
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 Linux 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 SCREENIO
option:
CALL 'SHCMD' 'ls' 'SCREENIO'
Retrieve the return code by using the RET
function:
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