Is it possible get the result of executing a SHCMD command through a program?
I have this code below, and basically call google.com using curl command, and return to screen some HTML elements.
It’s possible to get this HTML elements and put in a variable or array for example?
DEFINE DATA LOCAL
1 rc (I4)
END-DEFINE
CALL 'shcmd' 'curl google.com' 'SCREENIO'
ASSIGN rc = RET('SHCMD') /* retrieve return code
write rc
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
As Ralph already pointed out, you can use the REQUEST DOCUMENT statement to replace the “curl” command and use the XML Toolkit (see SYSEXXT) to parse the response document. No “work around” required. Works everywhere Natural runs.