Get SHCMD return on natural program

Hi,

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

Thanks.

Your syntax to retrieve the SHCMD return code is correct.

ASSIGN #RC = RET ("SHCMD")

I have no experience with “curl”, but Natural’s REQUEST DOCUMENT statement should be able to retrieve the HTML.

Hi,

we did a work-a-round for this. We redirekt the output into a file and then parse this file. Works only on Unix.

#command := “curl google.com > output.html”

#rc := RET(‘SHCMD’) /* retrieve return code
IF #rc = 0
THEN
DEFINE WORK FILE 1 ‘output.html’ TYPE ‘ASCII’
READ WORK 1 RECORD #LINE

END-WORK
CLOSE WORK 28
ELSE

END-IF

Best regards

Markus Wessjohann

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.

Thanks Markus, it worked perfectly.

Douglas and Ralph, I will seek to know more about the REQUEST DOCUMENT, and see if there is a better solution.

Thank you all.