简体   繁体   English

如何将退出代码从Ada进程返回到调用Windows进程?

[英]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. 我需要将Windows C ++程序与遗留的GNAT Ada程序连接起来。 The Windows program spawns the legacy Ada program as a separate process and then waits for it to return. Windows程序将遗留的Ada程序作为一个单独的进程生成,然后等待它返回。

I can have the Ada main program written as a function that returns an integer. 我可以将Ada主程序编写为返回整数的函数。 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? 我可以看到在Window中,我可以等待进程完成,调用WaitForSingleObject()并且我可以调用GetExitCodeProcess() - 但这些似乎都告诉我Ada程序返回的内容 - 我是否正确?

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? 谁能说明如何让Ada程序的返回值回到调用的Windows程序?

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. 如果遗留应用程序将结果写入标准输出( STDOUT ),则可以将Ada程序的STDOUTSTDERR重定向到管道。

You can later extract the information from the pipe and parse it in your C++ program. 您可以稍后从管道中提取信息并在C ++程序中解析它。

You can find here an example on how to redirect STDOUT to a pipe in Windows: 您可以在此处找到有关如何将STDOUT重定向到Windows中的管道的示例:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx 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). Ada程序通常设置退出代码,就像用任何其他语言编写的程序一样,尽管标准库仅提供SuccessFailure (映射到适当的操作系统特定值)。

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. Microsoft文档不清楚。 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. 需要修改Ada程序,将主程序更改为返回int的main函数。 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. 事实上,传递给GetExitCodeProcess()的地址的DWORD变量实际上获得了Ada程序的返回值。 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... 通过阅读MS文档不清楚返回值是来自Ada程序还是某些与该过程有关的Windows错误代码......

Anyhow, thanks for the help. 无论如何,谢谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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