2

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?

rudicangiotti
  • 566
  • 8
  • 20
  • 1
    It is a long shot, but, does your batch script modify the `%PATH%` variable? – MC ND Jul 24 '14 at 06:11
  • Thanks for your comment. Yes, unfortunately I have just noticed that some lines above, I have defined the output variable of a `set /p` command as `%PATH%`, so it actually replaces the environment variable. – rudicangiotti Jul 24 '14 at 09:46

1 Answers1

1

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 of fciv.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 containing fciv.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 of fciv.* 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

  • if the batch file is only executed on one computer,
  • or the application is installed surely on all computers in same directory,
  • or the application is installed on a server only while the batch file is executed by the clients and calling / starting the application via a public share directly on server.

Conclusion:

  • Poor is:   fciv
  • Better is: fciv.exe
  • Best is:   "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.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143