can a .com executable run on other OS besides windows?
I understand that the extension of the executables .com .exe etc is meant for the operating system. It has got nothing to do with the underlying ISA (be it x86 or开发者_开发知识库 SPARC). Am I correct? does .com executable run only on windows OS ? Are .com executables legacy?
The .com, .exe extension tells the DOS or Windows operating systems that the file is an executable. The file extension (.com, .exe) alone doesn't tell the operating system what the underlying instruction set is. For Windows executables with a .exe extension the instruction set is specified in the first few bytes of the file (the PE header).
Originally DOS .com files simply contained a set of instructions that the operating system (i.e. DOS) would load at a fixed address and execute from the first instruction. These type of .com files are 'legacy'. They cannot be run on modern operating systems without emulation. This type of .com files can be found on CP/M and later (and more commonly) DOS but only run on the operating system and instruction architecture they were originally designed for. You can run them on other operating systems through emulation. e.g. dosbox runs DOS .com files on Linux. Later versions of DOS and then Windows look inside .com files to see if they are really LE/PE executables. If they are it executes them as if they had a .exe extension instead. Visual Studio ships some files with the .com extension. See https://devblogs.microsoft.com/oldnewthing/20080324-00/?p=23033 for more on this.
Technically, an executable is simply a binary file. It's only on the windows os that you need a file extension for executables. Otherwise you are correct. I'm not sure exactly how legacy com is, it may be officially deprecated, but have bits still running around modern versions of windows.
.com and .exe's are usually x86 code. Though the wikipedia article http://en.wikipedia.org/wiki/COM_file mentions the .com extension came up in cp/m which is older.
They are NOT "intentionally portable", though nowadays DOS and Windows emulators exist on other platforms that could run these.
Filetypes like .py (python) and .jar (compiled java) are designed to be run on any CPU and any OS, as long as they have their "platform" installed (Python or JRE, respectively).
精彩评论