.NET Console Application - How to get Return Code returned i

Posted by dkeasberry on 15-May-2013 05:50

Hi All

I am new to this so sorry if this is in the wrong forum.

[OpenEdge 10.2a]

I am trying to do the following:

Within progress code call an .NET console application that connects and transfers a file to an SFTP server.

I have used the Shell32.dll to call the ShellExecuteA which you can see in my code below. whilst this calls the EXE (Console application) I cannot see to pick up the return code from the EXE application. Depending on what happens I return an int from the EXE which I want to pick up in the calling process code so I can then complete further actions depentant on this returned int.

Can anyone help me with this as I cannot seem to find examples or use OS-Command to do what I require.

Many thanks in advance.

My code below -

        PROCEDURE ShellExecuteA EXTERNAL "SHELL32.DLL": /*"C:\WINDOWS\System32\*/
            DEF INPUT PARAM hWnd AS LONG NO-UNDO.
            DEF INPUT PARAM lpOperation AS CHARACTER NO-UNDO.
            DEF INPUT PARAM lpFile AS CHARACTER NO-UNDO.
            DEF INPUT PARAM lpParameters AS CHARACTER NO-UNDO.
            DEF INPUT PARAM lpDirectory AS CHARACTER NO-UNDO.
            DEF INPUT PARAM nShowCmd AS LONG NO-UNDO.
            DEF RETURN PARAM hInstance AS CHARACTER NO-UNDO.
        END PROCEDURE.


        DEF VAR sReturnCode AS CHARACTER NO-UNDO.
        DEF VAR sNullString AS CHARACTER NO-UNDO.
        DEF VAR sParam AS CHARACTER NO-UNDO.

        /*Build up param string*/
        Assign sParam = quoter(vcOutputFile) + " " +
                        quoter(vcRSAOutFile) + " " +
                        quoter(Company_UD.SFTPPassword) + " " +
                        quoter(Company_UD.SFTPUsername) + " " +
                        quoter(Company_UD.SFTPUrl) + " " +
                        quoter(Company_UD.SFTPPort).

        RUN ShellExecuteA (INPUT 1,
                        INPUT sNullString,
                        INPUT vcSFTPUploadExe,
                        INPUT sParam,
                        INPUT sNullString,
                        INPUT 1,
                        OUTPUT sReturnCode).

All Replies

Posted by jquerijero on 30-Oct-2013 14:51

You can also use System.Diagnostics.Process to run external application. This should easily give you the return value of the application.

Posted by Youssif Shanshiry on 31-Oct-2013 16:45

The last param of the external procedure definition needs to be long:

DEF RETURN PARAM hInstance AS LONG NO-UNDO.

This thread is closed