Why does a file get opened when I write its name, without extensions, in the command line?
On Windows 10, I have a file called truffle.js
in my current folder.
I write truffle
in the cmd window, expecting to invoke the truffle
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
.
windows cmd.exe
add a comment |
On Windows 10, I have a file called truffle.js
in my current folder.
I write truffle
in the cmd window, expecting to invoke the truffle
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
.
windows cmd.exe
1
Server 2008 won't run executables from CMD prompt without .exe extension
– phuclv
Jun 11 '18 at 14:57
Possible duplicate of Command prompt launches "java.exe" with .exe extension, but not without .exe extension
– phuclv
Jun 11 '18 at 14:58
Because Windows will open any file with extensions that have an associated application. It's saving you from having to typec:pathapplication.exe c:pathfilename.ext
rather than justfilename
.
– ashleedawg
Jun 13 '18 at 4:53
add a comment |
On Windows 10, I have a file called truffle.js
in my current folder.
I write truffle
in the cmd window, expecting to invoke the truffle
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
.
windows cmd.exe
On Windows 10, I have a file called truffle.js
in my current folder.
I write truffle
in the cmd window, expecting to invoke the truffle
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
.
windows cmd.exe
windows cmd.exe
edited Jun 11 '18 at 14:08
JakeGould
31k1093137
31k1093137
asked Jun 11 '18 at 13:34
ripper234
4,3582973105
4,3582973105
1
Server 2008 won't run executables from CMD prompt without .exe extension
– phuclv
Jun 11 '18 at 14:57
Possible duplicate of Command prompt launches "java.exe" with .exe extension, but not without .exe extension
– phuclv
Jun 11 '18 at 14:58
Because Windows will open any file with extensions that have an associated application. It's saving you from having to typec:pathapplication.exe c:pathfilename.ext
rather than justfilename
.
– ashleedawg
Jun 13 '18 at 4:53
add a comment |
1
Server 2008 won't run executables from CMD prompt without .exe extension
– phuclv
Jun 11 '18 at 14:57
Possible duplicate of Command prompt launches "java.exe" with .exe extension, but not without .exe extension
– phuclv
Jun 11 '18 at 14:58
Because Windows will open any file with extensions that have an associated application. It's saving you from having to typec:pathapplication.exe c:pathfilename.ext
rather than justfilename
.
– ashleedawg
Jun 13 '18 at 4:53
1
1
Server 2008 won't run executables from CMD prompt without .exe extension
– phuclv
Jun 11 '18 at 14:57
Server 2008 won't run executables from CMD prompt without .exe extension
– phuclv
Jun 11 '18 at 14:57
Possible duplicate of Command prompt launches "java.exe" with .exe extension, but not without .exe extension
– phuclv
Jun 11 '18 at 14:58
Possible duplicate of Command prompt launches "java.exe" with .exe extension, but not without .exe extension
– phuclv
Jun 11 '18 at 14:58
Because Windows will open any file with extensions that have an associated application. It's saving you from having to type
c:pathapplication.exe c:pathfilename.ext
rather than just filename
.– ashleedawg
Jun 13 '18 at 4:53
Because Windows will open any file with extensions that have an associated application. It's saving you from having to type
c:pathapplication.exe c:pathfilename.ext
rather than just filename
.– ashleedawg
Jun 13 '18 at 4:53
add a comment |
1 Answer
1
active
oldest
votes
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.
3
To clarify, you mean that windows will take an input, add those file extensions to the input to see if it matches, before looking in the PATH.
– TankorSmash
Jun 11 '18 at 16:22
9
Also note that OP's original logic holds - these are all executables (in some sense of the word...), some of them just happen to also be human readable.
– Adonalsium
Jun 11 '18 at 19:33
2
@TankorSmash Windows, as in theCreateProcess
and I think also theShellExecute(Ex)
APIs, doesn't look at PATHEXT. The extension search is only implemented within the default shells (cmd.exe and powershell.exe). That said,CreateProcess
andShellExecute(Ex)
will append.exe
specifically.
– Bob
Jun 12 '18 at 7:02
3
@hBy2Py if an attacker has enough access to plant a file on your system and execute it, you're already screwed, no matter the file extension or the value of the%PATHEXT%
environment variable.
– zakinster
Jun 12 '18 at 16:40
2
@JustinC.B. Apples and oranges. Notepad++ is not a Microsoft product (and not bundled with Windows, etc.). Naming aside, it's as much (or little) of a replacement for Notepad as Sublime Text or even VSCode are. PowerShell, on the other hand, has first-party support and is increasingly becoming the (bundled) default over the legacy Command Prompt, and much of the new commands introduced over the last few years are PowerShell-only.
– Bob
Jun 15 '18 at 1:24
|
show 14 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1330358%2fwhy-does-a-file-get-opened-when-i-write-its-name-without-extensions-in-the-com%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
3
To clarify, you mean that windows will take an input, add those file extensions to the input to see if it matches, before looking in the PATH.
– TankorSmash
Jun 11 '18 at 16:22
9
Also note that OP's original logic holds - these are all executables (in some sense of the word...), some of them just happen to also be human readable.
– Adonalsium
Jun 11 '18 at 19:33
2
@TankorSmash Windows, as in theCreateProcess
and I think also theShellExecute(Ex)
APIs, doesn't look at PATHEXT. The extension search is only implemented within the default shells (cmd.exe and powershell.exe). That said,CreateProcess
andShellExecute(Ex)
will append.exe
specifically.
– Bob
Jun 12 '18 at 7:02
3
@hBy2Py if an attacker has enough access to plant a file on your system and execute it, you're already screwed, no matter the file extension or the value of the%PATHEXT%
environment variable.
– zakinster
Jun 12 '18 at 16:40
2
@JustinC.B. Apples and oranges. Notepad++ is not a Microsoft product (and not bundled with Windows, etc.). Naming aside, it's as much (or little) of a replacement for Notepad as Sublime Text or even VSCode are. PowerShell, on the other hand, has first-party support and is increasingly becoming the (bundled) default over the legacy Command Prompt, and much of the new commands introduced over the last few years are PowerShell-only.
– Bob
Jun 15 '18 at 1:24
|
show 14 more comments
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.
3
To clarify, you mean that windows will take an input, add those file extensions to the input to see if it matches, before looking in the PATH.
– TankorSmash
Jun 11 '18 at 16:22
9
Also note that OP's original logic holds - these are all executables (in some sense of the word...), some of them just happen to also be human readable.
– Adonalsium
Jun 11 '18 at 19:33
2
@TankorSmash Windows, as in theCreateProcess
and I think also theShellExecute(Ex)
APIs, doesn't look at PATHEXT. The extension search is only implemented within the default shells (cmd.exe and powershell.exe). That said,CreateProcess
andShellExecute(Ex)
will append.exe
specifically.
– Bob
Jun 12 '18 at 7:02
3
@hBy2Py if an attacker has enough access to plant a file on your system and execute it, you're already screwed, no matter the file extension or the value of the%PATHEXT%
environment variable.
– zakinster
Jun 12 '18 at 16:40
2
@JustinC.B. Apples and oranges. Notepad++ is not a Microsoft product (and not bundled with Windows, etc.). Naming aside, it's as much (or little) of a replacement for Notepad as Sublime Text or even VSCode are. PowerShell, on the other hand, has first-party support and is increasingly becoming the (bundled) default over the legacy Command Prompt, and much of the new commands introduced over the last few years are PowerShell-only.
– Bob
Jun 15 '18 at 1:24
|
show 14 more comments
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.
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.
edited Dec 9 '18 at 13:35
grawity
233k36492547
233k36492547
answered Jun 11 '18 at 14:02
Daniel B
33.4k76087
33.4k76087
3
To clarify, you mean that windows will take an input, add those file extensions to the input to see if it matches, before looking in the PATH.
– TankorSmash
Jun 11 '18 at 16:22
9
Also note that OP's original logic holds - these are all executables (in some sense of the word...), some of them just happen to also be human readable.
– Adonalsium
Jun 11 '18 at 19:33
2
@TankorSmash Windows, as in theCreateProcess
and I think also theShellExecute(Ex)
APIs, doesn't look at PATHEXT. The extension search is only implemented within the default shells (cmd.exe and powershell.exe). That said,CreateProcess
andShellExecute(Ex)
will append.exe
specifically.
– Bob
Jun 12 '18 at 7:02
3
@hBy2Py if an attacker has enough access to plant a file on your system and execute it, you're already screwed, no matter the file extension or the value of the%PATHEXT%
environment variable.
– zakinster
Jun 12 '18 at 16:40
2
@JustinC.B. Apples and oranges. Notepad++ is not a Microsoft product (and not bundled with Windows, etc.). Naming aside, it's as much (or little) of a replacement for Notepad as Sublime Text or even VSCode are. PowerShell, on the other hand, has first-party support and is increasingly becoming the (bundled) default over the legacy Command Prompt, and much of the new commands introduced over the last few years are PowerShell-only.
– Bob
Jun 15 '18 at 1:24
|
show 14 more comments
3
To clarify, you mean that windows will take an input, add those file extensions to the input to see if it matches, before looking in the PATH.
– TankorSmash
Jun 11 '18 at 16:22
9
Also note that OP's original logic holds - these are all executables (in some sense of the word...), some of them just happen to also be human readable.
– Adonalsium
Jun 11 '18 at 19:33
2
@TankorSmash Windows, as in theCreateProcess
and I think also theShellExecute(Ex)
APIs, doesn't look at PATHEXT. The extension search is only implemented within the default shells (cmd.exe and powershell.exe). That said,CreateProcess
andShellExecute(Ex)
will append.exe
specifically.
– Bob
Jun 12 '18 at 7:02
3
@hBy2Py if an attacker has enough access to plant a file on your system and execute it, you're already screwed, no matter the file extension or the value of the%PATHEXT%
environment variable.
– zakinster
Jun 12 '18 at 16:40
2
@JustinC.B. Apples and oranges. Notepad++ is not a Microsoft product (and not bundled with Windows, etc.). Naming aside, it's as much (or little) of a replacement for Notepad as Sublime Text or even VSCode are. PowerShell, on the other hand, has first-party support and is increasingly becoming the (bundled) default over the legacy Command Prompt, and much of the new commands introduced over the last few years are PowerShell-only.
– Bob
Jun 15 '18 at 1:24
3
3
To clarify, you mean that windows will take an input, add those file extensions to the input to see if it matches, before looking in the PATH.
– TankorSmash
Jun 11 '18 at 16:22
To clarify, you mean that windows will take an input, add those file extensions to the input to see if it matches, before looking in the PATH.
– TankorSmash
Jun 11 '18 at 16:22
9
9
Also note that OP's original logic holds - these are all executables (in some sense of the word...), some of them just happen to also be human readable.
– Adonalsium
Jun 11 '18 at 19:33
Also note that OP's original logic holds - these are all executables (in some sense of the word...), some of them just happen to also be human readable.
– Adonalsium
Jun 11 '18 at 19:33
2
2
@TankorSmash Windows, as in the
CreateProcess
and I think also the ShellExecute(Ex)
APIs, doesn't look at PATHEXT. The extension search is only implemented within the default shells (cmd.exe and powershell.exe). That said, CreateProcess
and ShellExecute(Ex)
will append .exe
specifically.– Bob
Jun 12 '18 at 7:02
@TankorSmash Windows, as in the
CreateProcess
and I think also the ShellExecute(Ex)
APIs, doesn't look at PATHEXT. The extension search is only implemented within the default shells (cmd.exe and powershell.exe). That said, CreateProcess
and ShellExecute(Ex)
will append .exe
specifically.– Bob
Jun 12 '18 at 7:02
3
3
@hBy2Py if an attacker has enough access to plant a file on your system and execute it, you're already screwed, no matter the file extension or the value of the
%PATHEXT%
environment variable.– zakinster
Jun 12 '18 at 16:40
@hBy2Py if an attacker has enough access to plant a file on your system and execute it, you're already screwed, no matter the file extension or the value of the
%PATHEXT%
environment variable.– zakinster
Jun 12 '18 at 16:40
2
2
@JustinC.B. Apples and oranges. Notepad++ is not a Microsoft product (and not bundled with Windows, etc.). Naming aside, it's as much (or little) of a replacement for Notepad as Sublime Text or even VSCode are. PowerShell, on the other hand, has first-party support and is increasingly becoming the (bundled) default over the legacy Command Prompt, and much of the new commands introduced over the last few years are PowerShell-only.
– Bob
Jun 15 '18 at 1:24
@JustinC.B. Apples and oranges. Notepad++ is not a Microsoft product (and not bundled with Windows, etc.). Naming aside, it's as much (or little) of a replacement for Notepad as Sublime Text or even VSCode are. PowerShell, on the other hand, has first-party support and is increasingly becoming the (bundled) default over the legacy Command Prompt, and much of the new commands introduced over the last few years are PowerShell-only.
– Bob
Jun 15 '18 at 1:24
|
show 14 more comments
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1330358%2fwhy-does-a-file-get-opened-when-i-write-its-name-without-extensions-in-the-com%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Server 2008 won't run executables from CMD prompt without .exe extension
– phuclv
Jun 11 '18 at 14:57
Possible duplicate of Command prompt launches "java.exe" with .exe extension, but not without .exe extension
– phuclv
Jun 11 '18 at 14:58
Because Windows will open any file with extensions that have an associated application. It's saving you from having to type
c:pathapplication.exe c:pathfilename.ext
rather than justfilename
.– ashleedawg
Jun 13 '18 at 4:53