Assuming that the fciv.exe
file has been placed in the system directory C:\WINDOWS\system32
, it works correctly both when it is recalled from command prompt and when it is used in Batch scripting files. For instance:
@echo off
fciv -md5 C:\DOCUME~1\myUsername
pause
The above statements work well.
But, if I use fciv
inside a for
cycle, as in the following example:
@echo off
for /f "tokens=1 delims=/ " %%g in ('fciv -md5 C:\DOCUME~1\myUsername') do (echo %%g)
The command is not recognized and an error returns from command prompt:
"fciv" is not recognized as internal or external command, etc.
The same statement works in command prompt - of course using a %g
variable.
In order to be correctly interpreted as a command in for
cycles inside Batch files, I am forced to use a full path to fciv.exe
file.
Is anyone able to explain me why this happens?
MC ND has given already the right answer in a comment which is repeated here as an answer.
The batch file of the questioner contains just
fciv
instead offciv.exe
or even better"Full\Path To\fciv.exe"
.Therefore Windows first searches in current working directory with
fciv.*
for a file with one of the extensions listed in environment variable PATHEXT separated by semi-colons and if no file with such a file extension can be found, in all directories listed in environment variable PATH separated also by semi-colons.And environment variable PATH as defined for the user account was additionally modified within the batch file above the line running
fciv
with removing the path to directory containingfciv.exe
. Therefore Windows could not find this application on execution of the batch file.Hint 1:
For applications called or started within a batch file it is nearly always best to specify the file name of the application with file extension as then Windows can directly search for example for
fciv.exe
instead offciv.*
to find a file with extension COM, EXE, BAT, ...Hint 2:
It is even better to specify the file name of a called or started application with full path if the path is fixed for example
Conclusion:
fciv
fciv.exe
"Full\Path To\fciv.exe"
The best reference of an application is not always possible, but referencing application file name with file extension is nearly always possible.