On Windows 10, I have a file called
truffle.js
in my current folder.I writetruffle
in the cmd window, expecting to invoke thetruffle
program which resides elsewhere on my path.Instead,
truffle.js
is opened in my favorite IDE (.js
files are associated with that IDE). I thought this behavior is only like this for executable files,.bat
,.com
and.exe
. Why does it happen for a.js
file?Note: I subsequently discovered I have no
truffle
at all installed on my path, but my question remains: why is Windows completing the extension which I did not specify on a non-executable file?Even after installing truffle and restarting cmd, I can’t get the real truffle to run in a folder that contains a file
truffle.js
.
Solution:
Because %PATHEXT%
is set to .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
by default. Note how it contains .js
.
That means if you type a name, CMD will look for files with these extensions appended, in that order, in the current folder. Only after that will it consider what’s in %PATH%
. This behavior cannot be changed. You can modify %PATHEXT%
though, like any other environment variable.
You can use the WHERE
command to check which path would be opened (e.g. where truffle
), which will automatically search both %PATH% and %PATHEXT% the same way CMD would.