Get response from subprocesses

Posted by Johan Vergeer on 06-Sep-2017 01:42

Hi everyone,

We would like to use OpenEdge for FTP or SSH to communicate with other servers. In this most concrete case we want to send over files using SSH. 

This works just file with OS-COMMAND.

OS-COMMAND SILENT VALUE("o:\uvsb3\mailrap\pscp.exe -batch -pw {&password} " + ftpdir# + bestand# + " {&user}@{&server}:{&basisdir}" + subdir# + "/" + bestand#).

What we would like to get is a response when there is an error, so we can report this to the user.

I know this is not possible with OS-COMMAND, but I'm wondering if there is something in Progress OpenEdge that can make this possible.

All Replies

Posted by danielb on 06-Sep-2017 02:03

You can capture anything that the process writes to stdout/stderr through OS-COMMAND:

DEFINE VARIABLE vStdOut AS CHARACTER INITIAL "std.out" NO-UNDO.

DEFINE VARIABLE vStdErr AS CHARACTER INITIAL "std.err" NO-UNDO.

DEFINE VARIABLE vLongchar AS LONGCHAR NO-UNDO.

OS-COMMAND SILENT VALUE('dir /s/b this_doesnt_exit') 1> VALUE(vStdOut) 2> VALUE(vStdErr).

COPY-LOB FROM FILE vStdErr TO OBJECT vLongchar.

IF LENGTH(vLongchar) GT 0 THEN

DO:

   MESSAGE STRING(vLongchar) VIEW-AS ALERT-BOX ERROR

       TITLE "Error from OS-COMAMND".

END.

This thread is closed