Please login or register.

Login with username, password and session length
gfx gfx
1617 Posts in 535 Topics by 779 Members - Latest Member: November 27, 2022, 08:03:14 PM
gfx* Home | Help | Search | Login | Register | gfx
Absoft User Forum  |  Support  |  Windows  |  running programs via fortran

Author Topic: running programs via fortran  (Read 5759 times)


  • Newbie
  • *
  • Posts: 1
running programs via fortran
« on: August 27, 2007, 03:27:11 PM »

I'm running Windows XP. And coding in F90.

I'd like to run some third party programs from the fortran executable and write the results to a single output file. So far, I think one way to do this is to save the file pathname to the third party program as a character string and write it to the cmd window. What's the best way to do this?

Also, is there a better way to do this?


Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: running programs via fortran
« Reply #1 on: August 27, 2007, 05:41:52 PM »
This depends on the capabilities of the third-party program.
If the third-party program accepts command-line arguments then:

      include  ""
      integer iret, iret2
      si.cb = 68 ! sizeof(si)
      si.lpReserved = 0
      si.lpDesktop = 0
      si.lpTitle = 0
      si.dwFlags = 0
      si.cbReserved2 = 0
      si.lpReserved2 = 0
      iret = CreateProcess(
     &  VAL4(0),
     &  VAL(LOC("myprogram.exe filename")//char(0)),
     &  VAL4(0),
     &  VAL4(0),
     &  VAL4(FALSE),
     &  VAL4(0),
     &  VAL4(0),
     &  si,
     &  pi)
     if ( then 
 ! if this deadlocks then change to a finite time and loop
        iret = WaitForSingleObject (val(pi.hProcess), val(INFINITE))
        iret = CloseHandle (val(pi.hProcess))
        iret2 = CloseHandle (val(pi.hThread))

Then do whatever you want with file "filename"

Mark Coxhead

  • Jr. Member
  • **
  • Posts: 82
Re: running programs via fortran
« Reply #2 on: August 30, 2007, 03:41:57 AM »

On the old User group message board there was a similar enquiry about six months ago.  My answer was along the lines described by Mike above, which is the way I have successfully implemented such an enhancement.

However I recall the originator had some trouble understanding and I suggested an alternative that I initially tried out here.  This is using the Win32 API function WinExec, which is simpler to use.

The code (I too use F77) is as follows:

       INTEGER*4       SW_MAZIMISE

      FILE_NAME = "<location><name of executable>"   


            t1 = TRIM(FILE_NAME)//char(0)     

            Iret = WinExec(val(loc(t1)),SW_MAXIMIZE)                     


Absoft User Forum  |  Support  |  Windows  |  running programs via fortran

gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!