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

getting arguments from ShellExecute

tazmania23
Beginner
503 Views

Hi Everyone,
I am calling an Visual Fortran exe file from VC++ using ShellExecute and passing some parameters with it. I want my Fortran program to retrieve the parameter. I am using GetArg to retrieve it but it only works when i pass the parameter from the command-line and not using VC++

Herez the test code:

VC++ part of the code

int main(void)
{

ShellExecute(NULL,"open","C:\Sassi\MAIN\HOUSEEx.exe","pb1","", SW_SHOW );

return 0;
}

Visual Fortran part of the code

use dflib
CHARACTER MODNAME*50,FINP*120,FOUT*120,FILE4N*100
MODNAME = ''
IST=0
print*,'enter program HouseEX'
print*, 'ist=',ist
CALL GETARG (1, MODNAME)
IST = len(trim(MODNAME))
open(10,file='abcd.dat')
write(10,*) modname
write(10,*) ist
close(10)
IF (IST.LT.1) THEN
PRINT *,' ENTER INPUT FILE NAME '
READ (*,22) FINP
PRINT *,' ENTER OUTPUT FILE NAME '
READ (*,22) FOUT
PRINT *,' ENTER FILE4 NAME (INCLUDING FULL PATH)'
READ (*,22) FILE4N
Else
Print *,' Argument received '
ENDIF
22 FORMAT(A)
End


Any suggestion or help would be greatly appreciated.

---TaZ

0 Kudos
1 Reply
rahzan
New Contributor I
503 Views

I cannot tell you why shellexecute does do it.

But I do a similar thing using CreateProcess and it works ok, from CVF. For example:

szArgs= 'cmd.exe /c "dir *.f90 " >list.txt 2>&1'C!watch SIZEOFSzArgs
fSuccess = CreateProcess(null_character, & ! image file name
szArgs, & ! command line (including program name)
NULL_security_attributes, & ! security for process
NULL_security_attributes, & ! security for main thread
.FALSE., & ! new process inherits handles?
dwCreate, & ! creation flags
NULL, & ! environment
szPath,& ! new current DirNamenull_character
si, & ! STARTUPINFO structure
pi) ! PROCESSINFORMATION structure
if (.not. fSuccess) then

Hope it helps.

Tim

0 Kudos
Reply