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

Can't create process for batch file witharguments

michael_green
Beginner
469 Views
Hi All,

The following:

if(.not.CreateProcess(null,trim(fmis$exec)//'\FMISAutoUpdate.bat '//trim(StartupFile)//char(0), &
null,null,false,0,null,null,si,pi))then

works well when StartupFile is a space padded string. But occasionally I want to pass an argument to the batch file, in which caseStartupFile contains a path\filename. When this occurs the created process flashes the DOS window then immediately exits - it does not even "pause" on the first line of the command script. Both fmis$exec and StartupFile contain embedded spaces - I have tried every combination of double quotes I can think of but that makes no difference, and in any case, when StartupFile is space filled, fmis$exec is acceptable without quotes. What am I doing wrong?

With many thanks in advance,

Mike
0 Kudos
1 Reply
anthonyrichards
New Contributor III
469 Views
Quoting - michaelgreen
Hi All,

The following:

if(.not.CreateProcess(null,trim(fmis$exec)//'FMISAutoUpdate.bat '//trim(StartupFile)//char(0), &
null,null,false,0,null,null,si,pi))then

works well when StartupFile is a space padded string. But occasionally I want to pass an argument to the batch file, in which caseStartupFile contains a pathfilename. When this occurs the created process flashes the DOS window then immediately exits - it does not even "pause" on the first line of the command script. Both fmis$exec and StartupFile contain embedded spaces - I have tried every combination of double quotes I can think of but that makes no difference, and in any case, when StartupFile is space filled, fmis$exec is acceptable without quotes. What am I doing wrong?

With many thanks in advance,

Mike

Try the following:

char*1 quote
quote='"'
trim(fmis$exec)//"FMISAutoUpdate.bat "//quote//trim(StartupFile)//quote//char(0)

if fmis$exec works with blanks, you may just be benifiting from the system trying various combinations, one of which works. For example, to quote from the Help for Creatprocess

" For example, consider the string "c:program filessub dirprogram name". This string can be interpreted in a number of ways. The system tries the possibilities in the following order:

c:program.exe filessub dirprogram name
c:program filessub.exe dirprogram name
c:program filessub dirprogram.exe name
c:program filessub dirprogram name.exe

"
0 Kudos
Reply