.com、.exe 和 .bat 之间的区别?

发布于 2024-08-18 23:21:07 字数 38 浏览 4 评论 0原文

a.bat、a.com 和 a.exe 扩展名之间有什么区别?

What is the difference between the a.bat, a.com and a.exe extensions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

离去的眼神 2024-08-25 23:21:07

最初,.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 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.

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.

韵柒 2024-08-25 23:21:07

.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.

听你说爱我 2024-08-25 23:21:07

实际上,.com 和 .exe 都是二进制可执行文件,而 .bat 基本上是批处理文件。现在假设您有许多具有相同名称但扩展名不同的文件。

例如,a.coma.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 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.

终难愈 2024-08-25 23:21:07

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.

你与清晨阳光 2024-08-25 23:21:07

.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

北城半夏 2024-08-25 23:21:07

虽然 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

被翻牌 2024-08-25 23:21:07
  • .BAT(“批处理”的缩写)文件是一个纯文本文件,其中包含
    系列 Windows 命令。
  • .EXE(“可执行文件”的缩写)文件是一个二进制文件,其中包含
    更复杂的可执行二进制代码。
  • .COM 文件是 DOS 可执行文件,现在与 .EXE 相同。
  • 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.
孤千羽 2024-08-25 23:21:07

我使用 nasm -f bin -o helloworld.com helloworld.asm 编译了一个简单的 .com 示例文件:

org 100h

section .text

mov ah, 0
mov dx, msg
int 21h

mov ah, 4Ch
int 21h

section .data
msg db "Hello, World!$"

东西很好而且简单。我得到了 .com 文件,但是当我尝试在 Windows 11 中运行它时,我得到:

PS C:\Workspace\asm> .\helloworld.com 资源不可用:程序
“helloworld.com”无法运行:尝试启动时发生错误
使用工作目录处理 'C:\Workspace\asm\helloworld.com'
'C:\工作区\asm'。指定的可执行文件无效
此操作系统平台的应用程序。行:1 字符:1

  • .\helloworld.com
  • <前><代码>

这是一个 26 字节的小文件 - 这就是它如此受欢迎的原因之一:

b400 ba0c 01cd 21b4 4ccd 2100 4865 6c6c
6f2c 2057 6f72 6c64 2124 

Windows 似乎不想再与它有任何关系。

I compiled a simple .com example file using nasm -f bin -o helloworld.com helloworld.asm:

org 100h

section .text

mov ah, 0
mov dx, msg
int 21h

mov ah, 4Ch
int 21h

section .data
msg db "Hello, World!
quot;

Something nice and simple. I got the .com file, but when I try to run it in Windows 11 I get:

PS C:\Workspace\asm> .\helloworld.com ResourceUnavailable: Program
'helloworld.com' failed to run: An error occurred trying to start
process 'C:\Workspace\asm\helloworld.com' with working directory
'C:\Workspace\asm'. The specified executable is not a valid
application for this OS platform.At line:1 char:1

  • .\helloworld.com

It's a small 26 byte file - which is one reason it was so popular:

b400 ba0c 01cd 21b4 4ccd 2100 4865 6c6c
6f2c 2057 6f72 6c64 2124 

It just appears Windows wants nothing to do with it anymore.

赏烟花じ飞满天 2024-08-25 23:21:07

.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文