.com、.exe 和 .bat 之间的区别?
a.bat、a.com 和 a.exe 扩展名之间有什么区别?
What is the difference between the a.bat, a.com and a.exe extensions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
a.bat、a.com 和 a.exe 扩展名之间有什么区别?
What is the difference between the a.bat, a.com and a.exe extensions?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
最初,
.COM
文件是 8086 代码(即 16 位 x86)的文本 blob。它应该在固定地址加载,加载器将直接跳转到其地址的第一个字节。它的尺寸也受到限制。.EXE
文件具有更多标头信息。因此,它具有诸如动态链接之类的所需结构,其中 DLL 中的代码可以在加载时修补到.EXE
的内存空间中。它最初来自 DOS,但现在已用于视窗。然而,DOS 和 Windows 最终采用了一种模型,其中
.COM
和.EXE
中的文件扩展名没有任何意义。程序加载器首先检查文件的前两个字节。如果它恰好是字符串MZ
(传说它代表的是缩写早期的 Microsoft 员工),它会将其视为EXE
,否则它将像COM
文件一样加载它。由于MZ
没有映射到合理的 x86 指令来启动程序,因此他们可以逃脱惩罚。最终效果:在某些版本的 DOS/Windows 中,.EXE
可以用.COM
命名,反之亦然。例如,在许多版本的 DOS/Windows 中,著名的COMMAND.COM
实际上是一个EXE
。我不确定前一段在多大程度上适用于基于 NT 的 Windows 版本。我想现在他们已经完全放弃了
.COM
东西。最后,
.BAT
文件是要执行的命令列表,就像您在命令提示符下键入它们一样。然而现在大多数人将它们命名为.CMD
。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.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.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 stringMZ
(legend has it this stands for the initials of an early Microsoft employee), it will treat it as anEXE
, otherwise it will load it as if it were aCOM
file. SinceMZ
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 famousCOMMAND.COM
was actually anEXE
.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.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 是一个批处理文件。它被解释。
.exe是一个常规的可执行程序文件。
.com 文件(至少对于 MS-DOS 而言)缺少许多元数据,并且被加载到主内存中的特定偏移量中。它比.exe小
.bat is a batch file. It is interpreted.
.exe is a regular executable program file.
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
我猜你指的是 Windows 系统?
“a.bat”应该是一个批处理文件,相当于 Windows/DOS 中的脚本文件。
如今,“a.com”和“a.exe”应该是等效的。然而,早在 Windows 3.x 时代,“com”文件是一个DOS 可执行文件,其中“exe”文件是可移植可执行文件或基于 Windows 的可执行文件。如今,这是一个陷阱,因为“www.example.com”格式的文件可能存在于您的硬盘上,并且许多人将此类文件误认为是网络链接。更糟糕的是,Windows 通常会尝试在“exe”文件之前执行“com”文件。
I assume you mean for Windows?
"a.bat" is supposed to be a batch file, the Windows/DOS equivalent of a script file.
"a.com" and "a.exe" are supposed to be equivalent these days. However, back in the Windows 3.x days, a "com" file was a DOS executable, 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.
实际上,.com 和 .exe 都是二进制可执行文件,而 .bat 基本上是批处理文件。现在假设您有许多具有相同名称但扩展名不同的文件。
例如,
a.com
、a.exe
,如果您通过命令提示符运行文件 a.它将首先执行a.com
(仅当它存在时),否则它将运行a.exe
。或者说a.exe
也不存在,那么它将寻找a.bat
执行。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.
For instance,
a.com
,a.exe
and if you are running through the command prompt file a. It will first executea.com
(only if it exists), else it will runa.exe
. Or saya.exe
is also not there then it will look fora.bat
execution.bat(ch) 文件是由命令解释器执行的脚本。
exe文件是编译后的二进制代码,可以直接在CPU上执行。
com 文件是过去用于创建小型 exe 的遗留物。
A bat(ch) file is a script that is executed by the command interpretor.
A exe file is compiled binary code to be executed directly on the cpu.
A com file is a relic from the past to create a small exe.
.BAT - 批处理文件:命令列表(基本上是带有命令行命令的文本文件)
.COM - 加载到固定内存块中的 DOS 可执行文件(源于多任务处理之前)
.EXE - 可执行文件 - 标准应用程序Windows平台
.BAT - Batch File: list of commands (basically a text file with command-line commands)
.COM - DOS Executable loaded into a fixed block of memory (stems back from before multi-tasking)
.EXE - Executable file - standard application on the Windows platform
虽然 EXE 和 BAT 文件通常具有相似的用途,但它们使用完全不同的文件格式。这两种文件类型都可用于在 Windows 中创建可执行内容,但 BAT 文件可以执行的命令受到限制。由于 BAT 文件包含人类可读的文本,因此可以轻松编辑它们,因此通常用于自定义脚本任务。另一方面,EXE 文件包含使用编译器构建的复杂二进制数据。由于 EXE 文件支持比 BAT 文件更复杂的命令,因此大多数 Windows 应用程序都以 EXE 格式保存。
我也在寻找相同的查询,并找到了粘贴在这里的内容。
请参考下面的链接,您会发现它很有用,它完美地回答了您的问题:
.BAT 和 .EXE 之间的区别
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.
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
系列 Windows 命令。
更复杂的可执行二进制代码。
series of Windows commands.
much more complex executable binary code.
我使用 nasm -f bin -o helloworld.com helloworld.asm 编译了一个简单的 .com 示例文件:
东西很好而且简单。我得到了 .com 文件,但是当我尝试在 Windows 11 中运行它时,我得到:
这是一个 26 字节的小文件 - 这就是它如此受欢迎的原因之一:
Windows 似乎不想再与它有任何关系。
I compiled a simple .com example file using
nasm -f bin -o helloworld.com helloworld.asm
:Something nice and simple. I got the .com file, but when I try to run it in Windows 11 I get:
It's a small 26 byte file - which is one reason it was so popular:
It just appears Windows wants nothing to do with it anymore.
.bat文件直接影响CPU的性能。
而.exe文件将由解释器编译然后在CPU上执行。
.bat file effects directly on the performance of CPU.
While, the .exe file will be compiled by interpreter and then executed on CPU.