Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Help with open/kill external EXE from Fortran routine

Oliviu
Beginner
1,553 Views

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.

0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
1,553 Views

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

0 Kudos
Oliviu
Beginner
1,553 Views

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.

0 Kudos
Steven_L_Intel1
Employee
1,553 Views

See Win32 Corner - CreateProcess for a worked example.

0 Kudos
Oliviu
Beginner
1,553 Views

Steve Lionel (Intel) wrote:

See Win32 Corner - CreateProcess for a worked example.

Thank you.

0 Kudos
Reply