简体   繁体   中英

How to return an exit code from an Ada process to the calling Windows process?

I need to interface a Windows C++ program to a legacy GNAT Ada program. The Windows program spawns the legacy Ada program as a separate process and then waits for it to return.

I can have the Ada main program written as a function that returns an integer. I can see that in Window, I can wait for the process to complete with a call to WaitForSingleObject() and that I could call GetExitCodeProcess() - but neither of those seem to tell me what the Ada program returned - am I correct?

The return values seem to be whether the calls themselves returned errors, not the called process.

Should I be looking into the process information handles or some such?

Can anyone illuminate me as to how to get an Ada program's return value back to the calling Windows program?

I assume you don't have access to the source of the legacy application or you prefer not to make any changes.

If the legacy application is writing the result to the standard output ( STDOUT ), you can redirect STDOUT and STDERR of the Ada program to a pipe.

You can later extract the information from the pipe and parse it in your C++ program.

You can find here an example on how to redirect STDOUT to a pipe in Windows:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx

Another way would be to redirect the output to a temporary and parse the file once you detect that the process has finished.

Ada programs generally set an exit code just like programs written in any other language, although the standard library only provides for Success and Failure (mapped to the appropriate, operating system specific values).

Have you checked if the developers of the application you are calling for some reason have decided to use the same exit code, no matter the outcome of the execution? (Reading the documentation may be useful. ;-)

The Microsoft documentation was not clear. That is what I needed help with.

The Ada program needed to be modified to have the main procedure changed to a main function returning an int. So, when it was spawned off in another process and then completed, I needed a way for that return value to get back to the parent process. In fact, the DWORD variable that had its address passed to GetExitCodeProcess() in fact gets the Ada program's return value. It was not clear from reading the MS documentation whether the return value was going to be from the Ada program or some Windows error code having to do with the process...

Anyhow, thanks for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM