COMMAND.COM

จากวิกิพีเดีย สารานุกรมเสรี

COMMAND.COM เป็นอินเทอร์พรีเตอร์บรรทัดคำสั่งปริยายสำหรับระบบปฏิบัติการดอส วินโดวส์ 95 วินโดวส์ 98 และวินโดวส์มี และเป็นส่วนติดต่อผู้ใช้ปริยายในดอส โดยมีหน้าที่เพิ่มเติมคือตั้งค่าระบบโดยเรียกใช้ไฟล์การกำหนดค่า AUTOEXEC.BAT เมื่อโปรแกรมแรกเริ่มทำงานหลังจากบูตระบบ รวมถึงทำหน้าที่เป็นต้นกำเนิดของกระบวนการทั้งหมดด้วย COMMAND.COM รุ่นใหม่บนระบบปฏิบัติการโอเอส/2 และวินโดวส์เอ็นทีจะเป็น cmd.exe ถึงแม้ว่า COMMAND.COM จะพร้อมใช้งานบนระบบปฏิบัติการเหล่านั้นซึ่งเป็นรุ่น IA-32 ก็ตาม

COMMAND.COM เป็นโปรแกรมดอส โปรแกรมที่เรียกใช้จาก COMMAND.COM จะเป็นโปรแกรมดอสที่ใช้ MS-DOS API ในการสื่อสารข้อมูลกับระบบปฏิบัติการ (ดอส)

โหมดการทำงาน[แก้]

COMMAND.COM มีโหมดการทำงานอยู่ด้วยกันสองโหมดในรูปแบบเชลล์ โดยโหมดแรกจะเป็นโหมดแบบโต้ตอบ ซึ่งสำหรับดำเนินการคำสั่งที่ผู้ใช้พิมพ์โดยทันที โหมดที่สองจะเป็นโหมดแบบกลุ่ม ซึ่งดำเนินการลำดับคำสั่งที่กำหนดไว้ล่วงหน้าซึ่งถูกเก็บไว้เป็นไฟล์ข้อความที่มีนามสกุลไฟล์ .BAT

คำสั่งภายใน[แก้]

คำสั่งภายในเป็นคำสั่งที่บรรจุไว้ภายในไบนารีของ COMMAND.COM โดยตรง ซึ่งพร้อมใช้งานตลอดเวลา แต่สามารถเรียกใช้ได้เพียงจากอินเทอร์พรีเตอร์คำสั่งโดยตรงเท่านั้น

คำสั่งทั้งหมดจะถูกดำเนินการหลังจากกดปุ่ม ↵ Enter ที่ท้ายบรรทัดคำสั่ง โดยคำสั่งใน COMMAND.COM จะไม่คำนึงถึงตัวอักษรพิมพ์ใหญ่-เล็ก หมายความว่าสามารถพิมพ์คำสั่งได้โดยจะเป็นตัวพิมพ์ใหญ่หรือตัวพิมพ์เล็กก็ได้

BREAK
ควบคุมการจัดการการขัดจังหวะการทำงานของโปรแกรมโดยการกดปุ่ม Ctrl+C หรือปุ่ม Ctrl+Break
CHCP
แสดงข้อมูลหรือเปลี่ยนโค้ดเพจปัจจุบันของระบบ
CHDIR, CD
เปลี่ยนไดเรกทอรีการทำงานปัจจุบันหรือแสดงไดเรกทอรีปัจจุบัน
CLS
ล้างหน้าจอ
COPY
คัดลอกไฟล์จากต้นทางไปยังปลายทาง (หากมีไฟล์ปลายทางอยู่แล้ว ดอสจะถามว่าต้องการแทนที่ไฟล์ดังกล่าวหรือไม่) (ดูเพิ่มเติมที่ XCOPY คำสั่งภายนอกซึ่งสามารถคัดลอกทรีไดเรกทอรีได้ด้วย)
CTTY
กำหนดอุปกรณ์ที่จะใช้สำหรับส่วนนำเข้าและแสดงผล
DATE
แสดงผลและตั้งค่าวันที่ของระบบ
DEL, ERASE
ลบไฟล์ เมื่อใช้กับไดเรกทอรี จะลบเฉพาะไฟล์ที่อยู่ในไดเรกทอรีดังกล่าว ส่วนคำสั่งภายนอก DELTREE จะลบทั้งไดเรกทอรีย่อยและไฟล์ที่อยู่ในไดเรกทอรีดังกล่าว รวมทั้งลบไดเรกทอรีดังกล่าวออกด้วย
DIR
แสดงรายชื่อไฟล์ที่อยู่ในไดเรกทอรีที่ระบุ
ECHO
เปิด/ปิดการแสดงผลข้อความ (ECHO ON หรือ ECHO OFF) หรือแสดงผลข้อความบนหน้าจอ (ECHO text)
EXIT
ออกจาก COMMAND.COM และกลับไปที่โปรแกรมที่เรียกใช้
LFNFOR
เปิดหรือปิดใช้งานการส่งกลับชื่อไฟล์แบบยาวโดยคำสั่ง FOR (วินโดวส์ 9x)
LOADHIGH, LH
โหลดโปรแกรมเข้าไปในเขตปฏิบัติการหน่วยความจำสูง (HILOAD ใน DR DOS)
LOCK
เปิดให้โปรแกรมภายนอกเข้าถึงโวลุ่มดิสก์ระดับต่ำ (เฉพาะ DOS 7.1 และวินโดวส์ 9x)
MKDIR, MD
สร้างไดเรกทอรีใหม่
PATH
แสดงผลหรือเปลี่ยนค่าของตัวแปรสภาพแวดล้อม PATH ซึ่งควบคุมสถานที่ที่ COMMAND.COM ใช้สำหรับค้นหาไฟล์ปฏิบัติการ
PROMPT
แสดงผลหรือเปลี่ยนค่าของตัวแปรสภาพแวดล้อม PROMPT ซึ่งควบคุมการปรากฏของพร้อมท์
REN, RENAME
เปลี่ยนชื่อไฟล์หรือไดเรกทอรี
RMDIR, RD
ลบไดเรกทอรีว่างเปล่า
SET
กำหนดค่าของตัวแปรสภาพแวดล้อมโดยไม่มีอาร์กิวเมนต์ รวมถึงแสดงตัวแปรสภาพแวดล้อมที่กำหนดไว้ทั้งหมด
TIME
แสดงผลและตั้งค่าเวลาของระบบ
TRUENAME
แสดงชื่อจริงเต็มของไฟล์ โดยแปลงที่อยู่การแมประบบไฟล์แบบลอจิคัล ASSIGN, JOIN และ SUBST[1]
TYPE
แสดงเนื้อหาของไฟล์บนคอนโซล
UNLOCK
ปิดใช้งานการเข้าถึงดิสก์ระดับต่ำ (เฉพาะ DOS 7.1 และวินโดวส์ 9x)
VER
แสดงรุ่นของระบบปฏิบัติการ
VERIFY
เปิดหรือปิดการยืนยันการเขียนไฟล์
VOL
แสดงข้อมูลเกี่ยวกับโวลุ่ม

คำสั่งไฟล์ชุดคำสั่ง[แก้]

โครงสร้างการควบคุมมักจะถูกใช้ภายในไฟล์ชุดคำสั่ง ถึงแม้ว่าจะสามารถใช้โครงสร้างเหล่านั้นแบบโต้ตอบได้ก็ตาม[2][1]

:label
กำหนดเป้าหมายสำหรับ GOTO
CALL
ดำเนินการไฟล์ชุดคำสั่งถัดไปก่อน แล้วจึงกลับมาที่ไฟล์แรกและดำเนินการต่อ
FOR
การทำซ้ำ: ทำซ้ำคำสั่งสำหรับแต่ละชุดของไฟล์
GOTO
ย้ายการดำเนินการไปยังป้ายชื่อที่ระบุ ป้ายชื่อจะถูกระบุที่ต้นบรรทัด พร้อมด้วยเครื่องหมายทวิภาค (:likethis).
IF
คำสั่งแบบเงื่อนไข ใช้ในการจำแนกคำสั่งในการดำเนินการโปรแกรม
PAUSE
หยุดการดำเนินการโปรแกรมและแสดงข้อความแจ้งผู้ใช้ให้กดปุ่มใดก็ได้เพื่อดำเนินการต่อ
REM
คอมเมนต์: ละเว้นข้อความใด ๆ ที่อยู่หลังคำสั่งนี้
SHIFT
แทนที่พารามิเตอร์การแทนที่แต่ละค่าด้วยค่าถัดไป (เช่น %0 ด้วย %1, %1 ด้วย %2 ฯลฯ)

คำสั่ง IF[แก้]

เมื่อจะจบการทำงาน คำสั่งภายนอกทั้งหมดจะต้องส่งรหัสการส่งกลับ (เป็นค่าระหว่าง 0 ถึง 255) ไปยังโปรแกรมที่เรียก โดยโปรแกรมส่วนใหญ่จะมีแบบแผนบางอย่างสำหรับรหัสการส่งกลับนั้นด้วย (ตัวอย่างเช่น ค่า 0 สำหรับการดำเนินการที่สำเร็จ)[3][4][5][6]

หากมีโปรแกรมใด ๆ ถูกเรียกโดย COMMAND.COM คำสั่งภายใน IF พร้อมคำสั่งแบบเงื่อนไข ERRORLEVEL จะสามารถนำมาใช้ทดสอบเงื่อนไขข้อผิดพลาดของโปรแกรมภายนอกที่เรียกล่าสุดได้

คำสั่งภายในจะไม่สร้างค่าใหม่ภายใต้ COMMAND.COM

ตัวแปร[แก้]

ไฟล์ชุดคำสั่งสำหรับ COMMAND.COM มีตัวแปรสี่ชนิดดังต่อไปนี้:

  • Environment variables: These have the %VARIABLE% form and are associated with values with the SET statement. Before DOS 3 COMMAND.COM will only expand environment variables in batch mode; that is, not interactively at the command prompt.[ต้องการอ้างอิง]
  • Replacement parameters: These have the form %0, %1...%9, and initially contain the command name and the first nine command line parameters passed to the script (e.g., if the invoking command was "myscript.bat John Doe", then %0 is "myscript.bat", %1 is "John" and %2 is "Doe"). The parameters to the right of the ninth can be mapped into range by using the SHIFT statement.
  • Loop variables: Used in loops, they have the %%a format when run in batch files. These variables are defined solely within a specific FOR statement, and iterate over a certain set of values defined in that FOR statement.
  • Under Novell DOS 7, OpenDOS 7.01, DR-DOS 7.02 and higher, COMMAND.COM also supports a number of system information variables,[2][7][1] a feature earlier found in 4DOS 3.00 and higher[8] as well as in Multiuser DOS,[1] although most of the supported variable names differ.

การเปลี่ยนเส้นทาง การเชื่อมต่อ และการเชื่อมโยง[แก้]

Because DOS is a single-tasking operating system, piping is achieved by running commands sequentially, redirecting to and from a temporary file. COMMAND.COM makes no provision for redirecting the standard error channel.

command < filename
Redirect standard input from a file or device
command > filename
Redirect standard output, overwriting target file if it exists.
command >> filename
Redirect standard output, appending to target file if it exists.
command1 | command2
Pipe standard output from command1 to standard input of command2
command1command2
Commands separated by ASCII-20 (¶, invoked by Ctrl+T) are executed in sequence (chaining of commands).[1] In other words, first command1 is executed until termination, then command2.[1] This is an undocumented feature in COMMAND.COM of MS-DOS/PC DOS 5.0 and higher.[1] It is also supported by COMMAND.COM of the Windows NT family as well as by DR-DOS 7.07. All versions of DR-DOS COMMAND.COM already supported a similar internal function utilizing an exclamation mark (!) instead (a feature originally derived from Concurrent DOS and Multiuser DOS) - however, in the single-user line this feature was only available internally (in built-in startup scripts like "!DATE!TIME") and indirectly through DOSKEY's $T parameter to avoid problems with ! as a valid filename character.[1] 4DOS supports a configurable command line separator (4DOS.INI CommandSep= or SETDOS /C), which defaults to ^.[8] COMMAND.COM in newer versions of Windows NT also supports a & separator for compatibility with the cmd syntax in OS/2 and the Windows NT family.[8] (cmd, however, does not support the ¶ separator.)

ข้อจำกัด[แก้]

ความยาวบรรทัดคำสั่งในโหมดแบบโต้ตอบจะถูกจำกัดไว้ที่ 126 ตัวอักษร[9]

ในวัฒนธรรมยอดนิยม[แก้]

"Loading COMMAND.COM" message can be seen on a HUD view of the Terminator and the internal viewport of RoboCop when he reboots.

In the CGI children's TV series ReBoot, which takes place inside computers, the leader of a system (the equivalent of a city) is called the COMMAND.COM.

The command.com domain once hosted a website with an image of a command prompt that has finished running the "dir" command on the root of an empty C drive. However, the resulting command incorrectly displayed the . and .. directories, which are never shown in the root of a drive.[10]

ดูเพิ่ม[แก้]

อ้างอิง[แก้]

  1. 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 Paul, Matthias (1997-07-30). NWDOS-TIPs — Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds. MPDOSTIP (ภาษาเยอรมัน) (3, release 157 ed.). คลังข้อมูลเก่าเก็บจากแหล่งเดิม (e-book)เมื่อ 2016-11-04. สืบค้นเมื่อ 2014-08-06. (NB. NWDOSTIP.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 NWDOSTIP.TXT file.)
  2. 2.0 2.1 "Chapter 7: Batch Processing". DR-DOS 7.02 User Guide. Caldera, Inc. 1998. คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2017-09-11. สืบค้นเมื่อ 2017-09-11.
  3. Paul, Matthias (1997-05-01) [1993]. BATTIPs — Tips & Tricks zur Programmierung von Batchjobs. MPDOSTIP (ภาษาเยอรมัน). 7: ERRORLEVEL abfragen. คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 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.)
  4. Auer, Eric; Paul, Matthias; Hall, Jim (2015-12-24) [2003-12-31]. "MS-DOS errorlevels". คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2015-12-24.
  5. Paul, Matthias (2003) [1997]. Auer, Eric (บ.ก.). "Exitcodes (errorlevels) of DOS utilities". คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2017-09-11. สืบค้นเมื่อ 2017-09-11. [1]
  6. Allen, William; Allen, Linda. "Windows 95/98/ME ERRORLEVELs". คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2005-10-29.
  7. DR-DOS 7.02 User Guide. Caldera, Inc. 1998. คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2016-11-04. สืบค้นเมื่อ 2013-08-10.
  8. 8.0 8.1 8.2 Brothers, Hardin; Rawson, Tom; Conn, Rex C.; Paul, Matthias; Dye, Charles E.; Georgiev, Luchezar I. (2002-02-27). 4DOS 8.00 online help. […] 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.) […]
  9. Paul, Matthias (1997-07-01) [1994]. MSDOSTIPs — Tips für den Umgang mit MS-DOS 5.0-7. MPDOSTIP (ภาษาเยอรมัน). คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2017-08-22. สืบค้นเมื่อ 2013-10-25. (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.)
  10. "COMMAND.COM". คลังข้อมูลเก่าเก็บจากแหล่งเดิมเมื่อ 2006-02-18.