gfxgfx
 
Please login or register.

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

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

gtg639j

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

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?

Thanks

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  "mrwe.inc"
       record/STARTUPINFO/si
      record/PROCESS_INFORMATION/pi
      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(DETACHED_PROCESS .OR. NORMAL_PRIORITY_CLASS),
     &  VAL4(0),
     &  VAL4(0),
     &  si,
     &  pi)
     if (iret.ne.0) then 
 ! if this deadlocks then change to a finite time and loop
        iret = WaitForSingleObject (val(pi.hProcess), val(INFINITE))
    endif
        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
       PARAMETER   ( SW_MAXIMIZE = 3)


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

      INQUIRE (FILE=FILE_NAME,EXIST=EXISTFLAG)     

      IF (EXISTFLAG) THEN
     
            t1 = TRIM(FILE_NAME)//char(0)     

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

     ENDIF

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

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