Hi Sally,
You want to use the execute frontcall and not shellexec. Think of shellexec as the equivalent of double-clicking (or right-click select option) on the file.
When using the execute frontcall, you want to set the second parameter to 1 so that it waits for the result. (similar to RUN RETURNING)
Finally you want to test the exit status of what you launched, not what is displayed to standard output. So use exit.
So try this...
FUNCTION client_file_exists(filename)
DEFINE filename STRING
DEFINE cmd STRING
DEFINE ok BOOLEAN
LET cmd = SFMT('cmd /C "if exist %1 (exit 0) else (exit 1)"',filename)
CALL ui.Interface.frontCall("standard","execute",[cmd,1],[ok])
RETURN ok
END FUNCTION
... you may need to improve it to handle spaces in filenames but a quick test passing gdc.exe and gdc2.exe as arguments returned TRUE/FALSE respectively.
Reuben
This came up in a support call recently where someone had been using the function I suggested above and it was not working with a filename that had spaces. (Thank you Microsoft for the space in "Program Files", mind you we have used "Four Js" in a directory name at some point too so I can't criticise too much).
After a little bit of experimentation, this worked better and catered for my limited number of test cases.
FUNCTION client_file_exists(filename)
DEFINE filename STRING
DEFINE cmd STRING
DEFINE ok BOOLEAN
LET cmd = SFMT('cmd /C if exist "%1" (exit 0) else (exit 1)',filename)
CALL ui.Interface.frontCall("standard","execute",[cmd,1],[ok])
RETURN ok
END FUNCTION
Same disclaimer as before, test to make sure it meets your needs.
Reuben
PS Two things that helped were testing the command in command prompt window to find out exactly what command I needed
C:\Program Files\FourJs\gdc\3.20.11\bin>cmd /c if exist "gdc.exe" (exit 0) else (exit 1)
C:\Program Files\FourJs\gdc\3.20.11\bin>echo %errorlevel%
0
C:\Program Files\FourJs\gdc\3.20.11\bin>cmd /c if exist "gdc2.exe" (exit 0) else (exit 1)
C:\Program Files\FourJs\gdc\3.20.11\bin>echo %errorlevel%
1
C:\Program Files\FourJs\gdc\3.20.11\bin>cmd /c if exist "C:/Program Files/FourJs/gdc/3.20.11/bin/gdc.exe" (exit 0) else (exit 1)
C:\Program Files\FourJs\gdc\3.20.11\bin>echo %errorlevel%
0
C:\Program Files\FourJs\gdc\3.20.11\bin>cmd /c if exist "C:/Program Files/FourJs/gdc/3.20.11/bin/gdc2.exe" (exit 0) else (exit 1)
C:\Program Files\FourJs\gdc\3.20.11\bin>echo %errorlevel%
1
and also using the GDC Debug Console to view the command as received by the GDC and noting if it was transformed at all e.g.
om 7 {{an 0 FunctionCall 110 {{isSystem "0"} {moduleName "standard"} {name "execute"} {paramCount "2"} {returnCount "1"}} {{FunctionCallParameter 111 {{dataType "STRING"} {isNull "0"} {value "cmd /c if exist \"C:/Program Files/FourJs/gdc/3.20.11/bin/gdc2.exe\" (exit 0) else (exit 1)"}} {}} {FunctionCallParameter 112 {{dataType "INTEGER"} {isNull "0"} {value "1"}} {}}}} {un 95 {{selection "99"}}}}