COMMAND.COM

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書
COMMAND.COM
Windows 8上的COMMAND.COM
Windows 8上的COMMAND.COM
其他名稱MS-DOS Prompt,
Windows Command Interpreter
開發者Seattle Computer Products, IBM, Microsoft, The Software Link, Datalight, Novell, Caldera
首次發布1980年,​44年前​(1980
程式語言x86 組合語言[1]
作業系統
平台16位元 x86
由…取代cmd.exe
類型命令列直譯器
command.com在Windows 95上的Windows控制台里執行(MS-DOS命令提示字元)

COMMAND.COM是MS-DOSWindows 95Windows 98Windows 98SEWindows Me下預設的命令列直譯器。在DOS環境下,它也是預設使用者介面。它一般還是系統啟動後執行的第一個程式(即init),因此負責執行AUTOEXEC.BAT設定檔以設定系統環境,也是所有處理程序的父處理程序。

COMMAND.COM在OS/2Windows NT上的繼任者是cmd.exe。即便如此,COMMAND.COM在這些系統的IA-32版本上的DOS虛擬機器中仍然可用。

檔名COMMAND.COM也被Disk Control Program​(德語 (DCP)——前東德公司VEB Robotron發行的MS-DOS變體使用。[2]

FreeDOS下與之相容的命令處理程式有時也稱作FreeCom

COMMAND.COM是DOS程式。由COMMAND.COM啟動的程式都是DOS程式,呼叫DOS API與磁碟作業系統通訊。

操作模式[編輯]

作為一個使用者介面,COMMAND.COM有兩種截然不同的操作模式。第一種是互動模式,使用者輸入的指令會被立即執行;第二種是批次處理模式,負責執行儲存在名稱以.BAT結尾文字檔案中的一組預定義命令。

內部命令[編輯]

內部命令是直接儲存於COMMAND.COM二進位檔案中的命令。因此,它們一直可用,但只能直接執行於命令直譯器。

↵ Enter鍵在一行末尾按下後,所有命令才被執行。COMMAND.COM不區分大小寫,也就是說命令可以按照任意大小寫組合輸入。

BREAK
通過Ctrl+CCtrl+Break控制程式中斷。
CHCP
顯示或更改當前系統的頁碼
CHDIR, CD
更改當前工作目錄或顯示當前處於的目錄。
CLS
清除螢幕顯示。
COPY
將一個檔案複製到另一個位置(若目的檔已存在,MS-DOS會詢問是否替換)。(另請參見XCOPY,一個可以複製目錄樹的外部命令)
CTTY
定義輸入輸出所用的裝置。
DATE
顯示和設定系統日期。
DEL, ERASE
刪除一個檔案。在對一個目錄操作時,僅刪除目錄下的所有檔案。與之相對,外部命令command不僅刪除目錄下的全部子目錄及所有檔案,也刪除目錄本身。
DIR
列出指定目錄下的檔案。
ECHO
切換文字顯示開啟(ECHO ON) 或關閉(ECHO OFF)。也用於在螢幕上顯示字元(ECHO text)。
EXIT
退出COMMAND.COM並返回到啟動它的程式。
LFNFOR
開啟/關閉FOR命令返回長檔名的功能(Windows 9x)。
LOADHIGH, LH
將一個程式載入記憶體的高位址區域(相當於DR-DOSHILOAD)。
LOCK
允許外部程式執行低層磁碟訪問(僅MS-DOS 7.1Windows 9x)。
MKDIR,MD
新建一個目錄。
PATH
顯示或更改控制COMMAND.COM尋找可執行檔位置的PATH環境變數值。
PROMPT
顯示或更改控制命令列外觀的PROMPT環境變數值。
RENAME, REN
重新命名一個檔案或目錄。
RMDIR, RD
刪除一個空目錄。
SET
設定一個環境變數的值;無參數時,顯示全部已定義的環境變數。
TIME
顯示和設定系統時間。
TRUENAME
Display the fully expanded physical name of a file, resolving ASSIGN, JOIN and SUBST logical filesystem mappings.[3]
TYPE
在控制台上顯示檔案內容。
UNLOCK
關閉低層磁碟訪問(僅MS-DOS 7.1和Windows 9x)。
VER
顯示作業系統版本。
VERIFY
開啟/關閉檔案寫入驗證。
VOL
顯示卷宗的資訊。

批次處理命令[編輯]

控制結構多用於批次檔中,即使也可以在互動模式下使用。[4][3]

:label
定義GOTO的目標。
CALL
執行另一個批次檔,然後返回到原檔案並繼續。
FOR
迭代:為每一個特定組的檔案重複一個命令。
GOTO
將執行過程強行跳轉到一個特定標籤。標籤在一行的開始處指定,以冒號開始(:likethis)。
IF
條件語句,建立程式分支。
PAUSE
暫停程式執行,向使用者顯示訊息「按任意鍵繼續」。
REM
注釋:此命令後所有文字被忽略。
SHIFT
將每個可換位參數(Replacement parameters)以其後一個替代(即用%1替代%0,用%2替代%1等)

IF命令[編輯]

在退出的時候,所有外部命令都會向呼叫者給出一個介於 0 到 255 之間的返回碼。絕大多數程式對於它們的返回碼有一些約定,例如使用 0 表示成功執行。[5][6][7][8]

如果程式是由 COMMAND.COM 呼叫的,那麼使用 ERRORLEVEL 作為條件句的 IF 內部命令可以用於判斷最後呼叫的外部程式的錯誤狀態。

在 COMMAND.COM 中,內部命令不產生新的值。

變數[編輯]

COMMAND.COM批次檔允許四種變數類型:

  • 環境變數:形如 %VARIABLE%,使用 SET 語句賦值。在 DOS 3 之前,COMMAND.COM 僅會在批次處理模式中展開環境變數,或者說在命令提示字元中不能使用。[來源請求]
  • 可換位參數:形如 %0, %1...%9,預設包含命令名稱和傳遞給指令碼的前九個命令列參數(例如,如果呼叫命令「myscript.bat John Doe」,那麼 %0 是 「myscript.bat」,%1 是「John」,%2 是「Doe」)。第九個之後的參數可以使用 SHIFT 語句移動到前九個的範圍內。
  • 迴圈變數:在批次檔中形如 %%a,使用於迴圈中。這些變數僅由一個特定的 FOR 語句定義,然後在該語句中遍歷一系列給定的值。
  • 4DOS 3.00 及其後續版本[9]Multiuser DOS[3] 中,COMMAND.COM 還支援一系列系統環境變數英語System Information Variable,後來 Novell DOS 7OpenDOS 7.01DR-DOS 7.02 也跟進了這個功能[4][10][3],雖然它們所支援的變數名幾乎完全不同。

重新導向、管道及連接[編輯]

由於DOS是單使用者作業系統,管道由按順序執行多個命令並重新導向到臨時檔案(或從臨時檔案重新導向)實現。COMMAND.COM不支援重新導向到標準錯誤輸出

command < filename
從一個檔案或裝置重新導向標準輸入
command > filename
重新導向標準輸出,若檔案存在則覆蓋目的檔
command >> filename
重新導向標準輸出,若檔案存在則追加到目的檔結尾
command1 | command2
command1標準輸出管道至command2標準輸入
command1command2
由ASCII-20(¶, 用 Ctrl+T輸入)分隔的命令將被連續執行(即命令的「連接」)。[3] 也就是說,command1執行完畢後才會執行command2[3] 這是MS-DOS/PC DOS 5.0及更高的COMMAND.COM中一個未在文件中寫明的功能。[3] 這項功能也得到Windows NT系列與DR-DOS 7.07下的COMMAND.COM支援。DR-DOS下所有版本的COMMAND.COM支援一個類似的內部函式,但由感嘆號 (!) 呼叫(一項最初由Concurrent DOSMultiuser DOS衍生的功能)。 然而,在單使用者命令列環境下,這個功能只在內部(如內建的"!DATE!TIME"啟動指令碼)或間接通過DOSKEY的$T參數可用,以避免因 !可作為有效檔案名字符產生問題。[3] 4DOS支援可組態的命令列分隔符(4DOS.INI CommandSep= 或 SETDOS /C),預設為「^」。[9]在更高版本的Windows NT下,COMMAND.COM還支援&分隔符,以提供與OS/2及Windows NT系列cmd語法的相容性(然而cmd不支援¶分隔符)。[9]

限制[編輯]

互動模式下命令列長度不得超過126字元。[11][12][13]在MS-DOS 6.2.2中,互動模式的命令列長度限制為127字元。

流行文化[編輯]

終結者重新啟動時,在終結者的HUD視圖中和機械戰警的內部視圖中顯示有「正在載入 COMMAND.COM」(Loading COMMAND.COM)。

在電腦製作的動畫連續劇ReBoot英語ReBoot中(該劇的背景發生在電腦內部),系統(相當於城市)的領導者被稱為 COMMAND.COM。

參見[編輯]

參考資料[編輯]

  1. ^ MS-DOS/COMMAND.ASM at master · microsoft/MS-DOS · GitHub. [2021-04-23]. (原始內容存檔於2021-02-27). 
  2. ^ Kurth, Rüdiger; Groß, Martin; Hunger, Henry. Betriebssystem DCP. www.robotrontechnik.de. 2016-11-29 [2007] [2019-04-28]. (原始內容存檔於2019-04-03) (德語). 
  3. ^ 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 Paul, Matthias R. NWDOS-TIPs — Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds. MPDOSTIP. Release 157 3. 1997-07-30 [1994-05-01] [2014-08-06]. (原始內容存檔於4 November 2016) (德語).  (NB. The provided link points to a HTML-converted version of the NWDOSTIP.TXT, which is part of the MPDOSTIP.ZIP collection.) [1]
  4. ^ 4.0 4.1 Chapter 7: Batch Processing. Caldera DR-DOS 7.02 User Guide. Caldera, Inc. 1998 [1993, 1997] [2017-09-11]. (原始內容存檔於2017-09-11). 
  5. ^ Paul, Matthias R. BATTIPs — Tips & Tricks zur Programmierung von Batchjobs. MPDOSTIP. 1997-05-01. Kapitel 7: ERRORLEVEL abfragen [1993-10-01] [2017-08-23]. (原始內容存檔於2017-08-23) (德語).  (NB. BATTIPS.TXT is part of MPDOSTIP.ZIP. The provided link points to a HTML-converted older version of the BATTIPS.TXT file.) [2]
  6. ^ Auer, Eric; Paul, Matthias R.; Hall, Jim. MS-DOS errorlevels. 2015-12-24 [2003-12-31]. (原始內容存檔於2015-12-24). 
  7. ^ Paul, Matthias R. Auer, Eric , 編. Exitcodes (errorlevels) of DOS utilities. 2003 [1997] [2017-09-11]. (原始內容存檔於11 September 2017).  [3]
  8. ^ Allen, William; Allen, Linda. Windows 95/98/ME ERRORLEVELs. (原始內容存檔於2005-10-29). 
  9. ^ 9.0 9.1 9.2 Brothers, Hardin; Rawson, Tom; Conn, Rex C.; Paul, Matthias R.; Dye, Charles E.; Georgiev, Luchezar I. 4DOS 8.00 online help. 2002-02-27. […] Multiple Commands: You can type several commands on the same command line, separated by a caret [^]. For example, if you know you want to copy all of your .TXT files to drive A: and then run CHKDSK to be sure that drive A's file structure is in good shape, you could enter the following command: C:\>COPY *.TXT A: ^ CHKDSK A: You may put as many commands on the command line as you wish, as long as the total length of the command line does not exceed 511 characters. You can use multiple commands in aliases and batch files as well as at the command line. If you don't like using the default command separator, you can pick another character using the SETDOS /C command or the CommandSep directive in 4DOS.INI. […] SETDOS /C: (Compound character) This option sets the character used for separating multiple commands on the same line. The default is the caret [^]. You cannot use any of the redirection characters [<>|], or the blank, tab, comma, or equal sign as the command separator. The command separator is saved by SETLOCAL and restored by ENDLOCAL. This example changes the separator to a tilde [~]: C:\>SETDOS /C~ (You can specify either the character itself, or its ASCII code as a decimal number, or a hexadecimal number preceded by 0x.) […] CommandSep = c (^): This is the character used to separate multiple commands on the same line. […] Special Character Compatibility: If you use two or more of our products, or if you want to share aliases and batch files with users of different products, you need to be aware of the differences in three important characters: the Command Separator […], the Escape Character […], and the Parameter Character […]. The default values of each of these characters in each product is shown in the following chart: […] Product, Separator, Escape Parameter […] 4DOS: ^, ↑, & […] 4OS2, 4NT, Take Command: &, ^, $ […] (The up-arrow [↑] represents the ASCII Ctrl-X character, numeric value 24.) […] 
  10. ^ Caldera DR-DOS 7.02 User Guide. Caldera, Inc. 1998 [1993, 1997] [2013-08-10]. (原始內容存檔於2016-11-04). 
  11. ^ Paul, Matthias R. MSDOSTIPs — Tips für den Umgang mit MS-DOS 5.0-7. MPDOSTIP. 1997-07-01 [1994-01-01] [2013-10-25]. (原始內容存檔於2017-08-22) (德語).  (NB. MSDOSTIP.TXT is part of MPDOSTIP.ZIP, maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of the MSDOSTIP.TXT file.) [4]
  12. ^ Paul, Matthias R. Hinweise zu JPSofts 4DOS 5.5b/c, 5.51, 5.52a und NDOS. MPDOSTIP. 1997-05-01 [1995-03-01] [2015-05-08]. (原始內容存檔於2016-11-04) (德語).  (NB. The provided link points to a HTML-converted version of the 4DOS5TIP.TXT file, which is part of the MPDOSTIP.ZIP collection.) [5]
  13. ^ Schulman, Andrew; Brown, Ralf D.; Maxey, David; Michels, Raymond J.; Kyle, Jim. Undocumented DOS: A programmer's guide to reserved MS-DOS functions and data structures - expanded to include MS-DOS 6, Novell DOS and Windows 3.1需要免費註冊 2. Reading, Massachusetts, USA: Addison Wesley. 1994: 623, 626 [November 1993]. ISBN 0-201-63287-X.  (xviii+856+vi pages, 3.5"-floppy) Errata: [6][7]

延伸閱讀[編輯]

  • Cooper, Jim. Special Edition Using MS-DOS 6.22 3. Que Publishing. 2001. ISBN 978-0-78972573-8. 
  • Wolverton, Van. MS-DOS Commands: Microsoft Quick Reference 4th revised. Microsoft Press. 1990. ISBN 978-1-55615289-4. 
  • Paul, Matthias R. Re: Random Lockups with DR-DOS 7.03. FidoNet conference: ALT_DOS. 2004-06-17 [2019-04-28]. (原始內容存檔於2019-04-28). […] all MS-DOS versions prior to Windows 95 […] used a COM style COMMAND.COM file which has a special signature at the start of the file […] queried by the MS-DOS BIOS before it loads the shell, but not by the DR-DOS BIOS […] COMMAND.COM would […] check that it is running on the "correct" DOS version, so if you would load their COMMAND.COM under DR-DOS, you would receive a "Bad version" error message and their COMMAND.COM would exit, so DR-DOS would […] display an error message "Bad or missing command interpreter" (if DR-DOS was trying to load the SHELL= command processor after having finished CONFIG.SYS processing). In this case, you could enter the path to a valid DR-DOS COMMAND.COM (C:\DRDOS\COMMAND.COM) and everything was fine. Now, things have changed since MS-DOS 7.0 […] COMMAND.COM has internally become an EXE style file, so there is no magic […] signature […] to check […] thus no way for DR-DOS to rule out an incompatible COMMAND.COM. Further, their COMMAND.COM no longer does any version checks, but […] does not work under DR-DOS […] just crashes […] the PC DOS COMMAND.COM works fine under DR-DOS […]  [8][9]

外部連結[編輯]