Help with open/kill external EXE from Fortran routine

Help with open/kill external EXE from Fortran routine

Hi,

I need some help with controlling the execution of a .EXE file from my Fortran code. I have to configure and call an application from my code. To do this, I write all the necessary inputs into a text file, and I call the .EXE together with the input via a batch file, using SYSTEM = RESULT (C:\MyCode\App.bat). The problem is that the external application (App.exe) is not 100% reliable, and sometimes it just blocks during execution, also blocking my code on the SYSTEM = RESULT line. If I terminate the external program manually (for ex. I simply use End Process from Win Task Manager), my code can continue without problems. However, I have to perform hundreds of calls of the external App.exe, over several hours, and I need to find a way to automatically terminate it when things go bad. I want to know if there is any way of monitoring, from within my code, the progress of the App.exe, and to terminate it if, for example, it has not finished in a given amount of time (knowing that a "normal" execution should take a couple of minutes).

I am only a beginner in programming, please answer keeping this in mind. Thanks a lot for your help.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Use CreateProcess. http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

For running a batch file, the process you create should run "CMD.EXE /c YourBatchFile.bat arg, arg, arg"

A return value includes a pointer to the new process information. In there, is a handle to the new process. You can use this handle to terminate the process (e.g. after timeout with no progress).

Jim Dempsey

www.quickthreadprogramming.com

Quote:

jimdempseyatthecove wrote:

Use CreateProcess. http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

For running a batch file, the process you create should run "CMD.EXE /c YourBatchFile.bat arg, arg, arg"

A return value includes a pointer to the new process information. In there, is a handle to the new process. You can use this handle to terminate the process (e.g. after timeout with no progress).

Jim Dempsey

Thanks a lot, but I am not certain how to implement it using a Fortran compiler, all the details in the link refer only to C++ implementation.

See Win32 Corner - CreateProcess for a worked example.

Steve - Intel Developer Support

Quote:

Steve Lionel (Intel) wrote:

See Win32 Corner - CreateProcess for a worked example.

Thank you.

Leave a Comment

Please sign in to add a comment. Not a member? Join today