How do you make a .com file for MS-DOS? I have 开发者_运维技巧my own "operating system", PowerOS, and I want custom commands to be able to be entered. Is there any way to write a .com file?
The answer is fairly straightforward. You make a .COM
file containing an MS/PC/DR-DOS program image by writing a program in a programming language and compiling it with a compiler that targets MS/PC/DR-DOS. That's it.
Don't get confused about filename extensions. There's a .COM
program image file format, which is a fairly basic program image format. It was superseded by the "MZ" program image file format back in the 1980s. But it has nothing to do with the filename extension. A program image file for MS/PC/DR-DOS can have either the extension .COM
or the extension .EXE
, but the actual image file format is not dictated by this. (I mention DR-DOS. If memory serves correctly: In DR-DOS version 6 practically all of the program image files, even the ones named .COM
, were actually "MZ" format executables, and compressed ones at that.)
What you do depends from what program image file formats your operating system's program loader is capable of understanding. And, really, only you can tell the world that. If your operating system's program loader understands the "MZ" executable file format, and the programs that run on your operating system are 16-bit and run in real mode, then compiling commands for your operating system is as simple (ignoring system call and library issues) as, say, cranking up OpenWatcom's 16-bit compiler+linker, wcl
, and telling it to target MS/PC/DR-DOS with the -bcl=DOS
option.
Of course, if your programs are 32-bit and your operating system runs them in protected mode, or even if your programs are 16-bit and your operating system runs them in protected mode, then the "MZ" file format will be unsuitable for your needs, and you should use one of the several alternative program image file formats.
I know that for windows 7 and most likely for the other windows OS's you can write either a .bat, .exe, or .com and place it into windows/system32 folder. That file can be used as a command from the command prompt by simply typing in the name of the command you made.
To take in command line parameters, a batch file can use the variables %1, %2, %3 etc. The command works like any other command and can be used to further write batch files with it.
As far as MS-DOS goes, you may be able to place one of those file types in the root directory or find where the other commands are placed and put it there. I am not sure if a COM file is required, but if so, there are batch to com converters out there such as this old school one: Converter from batch to com
you can make an .bat file and paste this code to make custom commands example:
@echo off
set /p command=
if %command% ==
in the code type your command at the end and what you will the command to do.
you can copy the if command to ad more commands
精彩评论