windows .com、.exe 和 .bat 之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2115651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between .com, .exe, and .bat?
提问by Sarfraz
What is the difference between the a.bat, a.com and a.exe extensions?
a.bat、a.com 和 a.exe 扩展名之间有什么区别?
回答by asveikau
Originally, a .COM
file was a literal blob of 8086 code (that is, 16-bit x86). It is meant to be loaded at a fixed address, and the loader would jump straight to the first byte of its address. It's also limited in size.
最初,.COM
文件是 8086 代码(即 16 位 x86)的文字 blob。它意味着在固定地址加载,加载器将直接跳转到其地址的第一个字节。它也有大小限制。
An .EXE
file has more header information. So it has required structures for things like dynamic linking, where code from a DLL can be patched into the .EXE
's memory space at load time.. It originally comes from DOS, but it's today used in Windows.
一个.EXE
文件有更多的头信息。因此,它需要动态链接等结构,其中来自 DLL 的代码可以.EXE
在加载时修补到内存空间。它最初来自 DOS,但今天在 Windows 中使用。
However DOS and Windows eventually went to a model where the file extension in a .COM
and .EXE
didn't mean anything. The program loader first checks the first two bytes of the file. If it happens to be the string MZ
(legend has it this stands for the initials of an early Microsoft employee), it will treat it as an EXE
, otherwise it will load it as if it were a COM
file. Since MZ
doesn't map to a sensible x86 instruction to start a program, they can get away with this. Net effect: In some versions of DOS/Windows, an .EXE
can be named with .COM
and vice versa. For example, in many versions of DOS/Windows, the famous COMMAND.COM
was actually an EXE
.
然而,DOS 和 Windows 最终采用了一种模式,其中文件扩展名在 a 中.COM
并.EXE
没有任何意义。程序加载器首先检查文件的前两个字节。如果它恰好是字符串MZ
(传说它代表早期 Microsoft 员工的首字母缩写),它会将其视为EXE
,否则会将其加载为COM
文件。由于MZ
没有映射到合理的 x86 指令来启动程序,因此他们可以逃脱。净效果:在某些版本的 DOS/Windows 中,.EXE
可以命名为 with .COM
,反之亦然。例如,在许多版本的 DOS/Windows 中,著名的COMMAND.COM
实际上是一个EXE
.
I am not sure how much the previous paragraph applies to NT based versions of Windows. I'd imagine by now they've abandoned the .COM
stuff altogether.
我不确定上一段在多大程度上适用于基于 NT 的 Windows 版本。我想现在他们已经.COM
完全放弃了这些东西。
Lastly, a .BAT
file is a list of commands to be executed as if you typed them at your command prompt. However these days most people name them as .CMD
.
最后,.BAT
文件是要执行的命令列表,就像您在命令提示符下键入它们一样。然而,如今大多数人将它们命名为.CMD
.
回答by Extrakun
.bat is a batch file. It is interpreted.
.bat 是一个批处理文件。它被解释。
.exe is a regular executable program file.
.exe 是一个普通的可执行程序文件。
A .com file, at least for MS-DOS, has many meta-data missing and is loaded into a specific offset in the main memory. It is smaller than .exe
一个 .com 文件,至少对于 MS-DOS,缺少许多元数据,并被加载到主内存中的特定偏移量中。它比 .exe 小
回答by Medivh
I assume you mean for Windows?
我假设你的意思是 Windows?
"a.bat" is supposed to be a batch file, the Windows/DOS equivalent of a script file.
“a.bat”应该是一个批处理文件,相当于一个脚本文件的 Windows/DOS。
"a.com" and "a.exe" are supposed to be equivalent these days. However, back in the Windows 3.xdays, a "com" file was a DOSexecutable, where an "exe" file was a portable executable, or a Windows-based executable. This is a gotcha these days, as files in the format "www.example.com" can exist on your hard drive, and many people mistake such a file for a web link. Even worse, Windows typically tries executing "com" files before "exe" files.
“a.com”和“a.exe”现在应该是等价的。但是,在Windows 3.x时代,“com”文件是DOS可执行文件,其中“exe”文件是可移植的可执行文件或基于 Windows 的可执行文件。现在这是一个问题,因为“www.example.com”格式的文件可能存在于您的硬盘驱动器上,许多人将此类文件误认为是 Web 链接。更糟糕的是,Windows 通常会尝试在“exe”文件之前执行“com”文件。
回答by mynameiscoffey
.BAT - Batch File: list of commands (basically a text file with command-line commands)
.BAT - 批处理文件:命令列表(基本上是带有命令行命令的文本文件)
.COM - DOS Executable loaded into a fixed block of memory (stems back from before multi-tasking)
.COM - DOS 可执行文件加载到固定的内存块中(源于多任务处理之前)
.EXE - Executable file - standard application on the Windows platform
.EXE - 可执行文件 - Windows 平台上的标准应用程序
回答by Toon Krijthe
A bat(ch) file is a script that is executed by the command interpretor.
bat(ch) 文件是由命令解释器执行的脚本。
A exe file is compiled binary code to be executed directly on the cpu.
exe文件是编译后的二进制代码,直接在cpu上执行。
A com file is a relic from the past to create a small exe.
com 文件是过去创建小 exe 的遗物。
回答by Shrikant
While EXE and BAT files often serve a similar purpose, they use completely different file formats. Both file types can be used for creating executable content in Windows, but BAT files are limited in the commands they can perform. Since BAT files contain human-readable text, they can be easily edited and therefore are often used for custom scripting tasks. EXE files, on the other hand, contain complex binary data that is built using a compiler. Since EXE files support more complex commands than BAT files, most Windows applications are saved in the EXE format.
虽然 EXE 和 BAT 文件通常用于类似的目的,但它们使用完全不同的文件格式。这两种文件类型都可用于在 Windows 中创建可执行内容,但 BAT 文件在它们可以执行的命令方面受到限制。由于 BAT 文件包含人类可读的文本,因此它们可以轻松编辑,因此通常用于自定义脚本任务。另一方面,EXE 文件包含使用编译器构建的复杂二进制数据。由于 EXE 文件支持比 BAT 文件更复杂的命令,因此大多数 Windows 应用程序都以 EXE 格式保存。
I was also looking for the same query and found something that have pasted here.
我也在寻找相同的查询,并找到了粘贴在这里的内容。
Please refer the below link, you will find it useful, it perfectly answers your question:
Difference between .BAT and .EXE
请参考以下链接,您会发现它很有用,它完美地回答了您的问题:
.BAT 和 .EXE 的区别
回答by user2804021
Actually, .com and .exe are both binary executable files, whereas .bat is basically a batch file. Now suppose you have got many files with the same name, but different extensions.
实际上,.com 和 .exe 都是二进制可执行文件,而 .bat 基本上是一个批处理文件。现在假设您有许多名称相同但扩展名不同的文件。
For instance, a.com
, a.exe
and if you are running through the command prompt file a. It will first execute a.com
(only if it exists), else it will run a.exe
. Or say a.exe
is also not there then it will look for a.bat
execution.
例如,a.com
,a.exe
如果你是通过在命令提示符下的文件正在运行。它将首先执行a.com
(仅当它存在时),否则它将运行a.exe
。或者说a.exe
也不在那里,然后它会寻找a.bat
执行。
回答by Sanchit
- A .BAT (short for "batch") file is a plain text file that contains a series of Windows commands.
- An .EXE (short for "executable") file is a binary file that contains much more complex executable binary code.
- A .COM file was a DOS executable and nowadays its same as .EXE.
- .BAT(“批处理”的缩写)文件是包含一系列 Windows 命令的纯文本文件。
- .EXE(“可执行文件”的缩写)文件是一个二进制文件,其中包含更复杂的可执行二进制代码。
- .COM 文件是 DOS 可执行文件,现在它与 .EXE 相同。
回答by Baller
.bat file effects directly on the performance of CPU. While, the .exe file will be compiled by interpreter and then executed on CPU.
.bat 文件直接影响 CPU 的性能。而 .exe 文件将由解释器编译,然后在 CPU 上执行。