4 ms·
Here's an interesting quirk in Windows: There are two APIs to execute external programs, CreateProcess and ShellExecute. CreateProcess is the older of the two
by 13of40 6y ago
Here's an interesting quirk in Windows: There are two APIs to execute external programs, CreateProcess and ShellExecute. CreateProcess is the older of the two and only runs executables. ShellExecute opens the target with whatever app is associated with the extension.
When they shoehorned the ShellExecute behavior into cmd.exe, they basically just said "if (!CreateProcess(foo)) {ShellExecute (foo)}"
As a result, if you take "foo.exe" and rename it "foo.txt" then try to run it like "C:\>foo.txt" from the command line, it will run as an executable instead of opening in Notepad like you would expect. Do the same with a real text file (that doesn't start with "MZ") and it opens in Notepad.
- COGlory 6y agoThis is a frustrating behavior on Windows, not because it's possible, but because it's default. I vastly prefer the way KDE performs. Whatever the default program to open that file type is attempts to open it. You can easily change what the default is. It's frustrating when I instinctively change a file extension on Windows so I can do some other operation with it (say changing a configuration file to .txt to edit it) and Windows still doesn't know what to do with it. I'm not averse to the behavior, I just wish I could control when it happens.
- ectopod 6y agoBeing pedantic, CreateProcess is more fundamental but ShellExecute, dating back to 16-bit Windows, is older.