doskeydoskey

调用 Doskey.exe,这会回调先前输入的命令行命令、编辑命令行并创建宏。Calls Doskey.exe, which recalls previously entered command-line commands, edits command lines, and creates macros.

语法Syntax

doskey [/reinstall] [/listsize=<size>] [/macros:[all | <exename>] [/history] [/insert | /overstrike] [/exename=<exename>] [/macrofile=<filename>] [<macroname>=[<text>]]

参数Parameters

参数Parameter 说明Description
/reinstall/reinstall 安装 Doskey.exe 的新副本并清除命令历史记录缓冲区。Installs a new copy of Doskey.exe and clears the command history buffer.
/listsize =<size>/listsize=<size> 指定历史记录缓冲区中的最大命令数。Specifies the maximum number of commands in the history buffer.
/macros/macros 显示所有 doskey 宏的列表。Displays a list of all doskey macros. 您可以使用重定向符号 (>/macros) ,将列表重定向到文件。You can use the redirection symbol (>) with /macros to redirect the list to a file. 可以缩写 /macros/mYou can abbreviate /macros to /m.
/macros: all/macros:all 显示所有可执行文件的 doskey 宏。Displays doskey macros for all executables.
macros<exename>/macros:<exename> 显示exename指定的可执行文件的doskey宏。Displays doskey macros for the executable specified by exename.
/history/history 显示存储在内存中的所有命令。Displays all commands that are stored in memory. 您可以使用重定向符号 (>/history) ,将列表重定向到文件。You can use the redirection symbol (>) with /history to redirect the list to a file. 可以将 /history 缩写为 /hYou can abbreviate /history as /h.
/insert/insert 指定您键入的新文本将插入旧文本。Specifies that new text you type is inserted in old text.
/overstrike/overstrike 指定新文本覆盖旧文本。Specifies that new text overwrites old text.
/exename =<exename>/exename=<exename> 指定程序 (即, doskey 宏运行) 。Specifies the program (that is, executable) in which the doskey macro runs.
/macrofile =<filename>/macrofile=<filename> 指定一个文件,其中包含要安装的宏。Specifies a file that contains the macros that you want to install.
<macroname>=[<text>]<macroname>=[<text>] 创建一个宏,该宏执行 文本指定的命令。Creates a macro that carries out the commands specified by Text. MacroName 指定要分配给宏的名称。MacroName specifies the name you want to assign to the macro. Text 指定要记录的命令。Text specifies the commands you want to record. 如果 文本 保留为空白,则将清除任何已分配命令的 MacroNameIf Text is left blank, MacroName is cleared of any assigned commands.
/?/? 在命令提示符下显示帮助。Displays help at the command prompt.

备注Remarks

  • 某些基于字符的交互式程序(如程序调试器或文件传输程序) (FTP) 自动使用 Doskey.exe。Certain character-based, interactive programs, such as program debuggers or file transfer programs (FTP) automatically use Doskey.exe. 若要使用 Doskey.exe,程序必须是控制台进程并使用缓冲输入。To use Doskey.exe, a program must be a console process and use buffered input. 程序密钥分配将覆盖 doskey 密钥分配。Program key assignments override doskey key assignments. 例如,如果程序对某个函数使用了 F7 键,则不能在弹出窗口中获取 doskey 命令历史记录。For example, if the program uses the F7 key for a function, you cannot get a doskey command history in a pop-up window.

  • 您可以使用 Doskey.exe 编辑当前命令行,但不能在程序的命令提示符下使用命令行选项。You can use Doskey.exe to edit the current command line, but you can't use the command-line options from a program's command prompt. 必须先运行 doskey 命令行选项,然后再启动程序。You must run doskey command-line options before you start a program. 如果您在程序中使用 Doskey.exe,则该程序的密钥分配优先,一些 Doskey.exe 编辑密钥可能不起作用。If you use Doskey.exe within a program, that program's key assignments take precedence and some Doskey.exe editing keys might not work.

  • 使用 Doskey.exe,可以为启动或重复的每个程序维护命令历史记录。With Doskey.exe, you can maintain a command history for each program that you start or repeat. 你可以在程序的提示中编辑以前的命令,并启动为程序创建的 doskey 宏。You can edit previous commands at the program's prompt, and start doskey macros created for the program. 如果退出并重新启动同一个命令提示符窗口中的程序,则可使用上一个程序会话中的命令历史记录。If you exit and then restart a program from the same Command Prompt window, the command history from the previous program session is available.

  • 若要重新调用命令,你可以在开始 Doskey.exe 后使用以下任何项:To recall a command, you can use any of the following keys after you start Doskey.exe:

    密钥Key 说明Description
    向上键UP ARROW 撤回在显示的命令之前使用的命令。Recalls the command that you used before the one that is displayed.
    向下键DOWN ARROW 撤回在显示后使用的命令。Recalls the command that you used after the one that is displayed.
    Page UpPAGE UP 撤回在当前会话中使用的第一个命令。Recalls the first command that you used in the current session.
    Page DownPAGE DOWN 撤回当前会话中使用的最近使用的命令。Recalls the most recent command that you used in the current session.
  • 下表列出了 doskey 编辑密钥及其功能:The following table lists doskey editing keys and their functions:

    键或键组合Key or key combination 说明Description
    向左键LEFT ARROW 将插入点向后移动一个字符。Moves the insertion point back one character.
    向右键RIGHT ARROW 将插入点向后移动一个字符。Moves the insertion point forward one character.
    Ctrl+向左键CTRL+LEFT ARROW 将插入点向后移动一个单词。Moves the insertion point back one word.
    Ctrl+向右键CTRL+RIGHT ARROW 将插入点向前移动一个单词。Moves the insertion point forward one word.
    HomeHOME 将插入点移动到行首。Moves the insertion point to the beginning of the line.
    EndEND 将插入点移动到行的末尾。Moves the insertion point to the end of the line.
    ESCESC 清除显示的命令。Clears the command from the display.
    F1F1 将模板中的列中的一个字符复制到命令提示符窗口中的相同列。Copies one character from a column in the template to the same column in the Command Prompt window. (模板是包含所键入的最后一个命令的内存缓冲区 ) (The template is a memory buffer that holds the last command you typed.)
    F2F2 按下 F2 后,在模板中向前搜索你键入的下一个键。Searches forward in the template for the next key that you type after you press F2. Doskey.exe 插入模板中的文本(直到(但不包括)指定字符。Doskey.exe inserts the text from the template—up to, but not including, the character you specify.
    F3F3 将模板的其余部分复制到命令行。Copies the remainder of the template to the command line. Doskey.exe 从模板中的位置开始复制字符,该位置与命令行上的插入点所指示的位置相对应。Doskey.exe begins copying characters from the position in the template that corresponds to the position indicated by the insertion point on the command line.
    F4F4 在按 F4 后,删除当前插入点位置中的所有字符,直到下一次出现的字符。Deletes all characters from the current insertion point position up to, but not including, the next occurrence of the character that you type after you press F4.
    F5F5 将模板复制到当前命令行中。Copies the template into the current command line.
    F6F6 将文件尾字符 (CTRL + Z) 置于当前插入点位置。Places an end-of-file character (CTRL+Z) at the current insertion point position.
    F7F7 显示对话框中的 () 存储在内存中的此程序的所有命令。Displays (in a dialog box) all commands for this program that are stored in memory. 使用向上键和向下键选择所需的命令,然后按 ENTER 运行该命令。Use the UP ARROW key and the DOWN ARROW key to select the command you want, and press ENTER to run the command. 还可以记下命令前面的序列号,并将此数字与 F9 键结合使用。You can also note the sequential number in front of the command and use this number in conjunction with the F9 key.
    Alt+F7ALT+F7 为当前历史记录缓冲区删除存储在内存中的所有命令。Deletes all commands stored in memory for the current history buffer.
    F8F8 显示历史缓冲区中以当前命令中的字符开头的所有命令。Displays all commands in the history buffer that start with the characters in the current command.
    F9F9 将提示您输入历史缓冲区命令编号,然后显示与您指定的号码关联的命令。Prompts you for a history buffer command number, and then displays the command associated with the number that you specify. 按 ENTER 运行该命令。Press ENTER to run the command. 若要显示所有数字及其关联的命令,请按 F7。To display all the numbers and their associated commands, press F7.
    Alt+F10ALT+F10 删除所有宏定义。Deletes all macro definitions.
  • 如果按 INSERT 键,则可以在现有文本中间的 doskey 命令行上键入文本,而无需替换文本。If you press the INSERT key, you can type text on the doskey command line in the midst of existing text without replacing the text. 但在按 ENTER 后,Doskey.exe 会将键盘返回到 替换 模式。However, after you press ENTER, Doskey.exe returns your keyboard to Replace mode. 必须再次按 INSERT 才能返回到 插入 模式。You must press INSERT again to return to Insert mode.

  • 当使用 INSERT 键从一种模式更改为另一种模式时,插入点会改变形状。The insertion point changes shape when you use the INSERT key to change from one mode to the other.

  • 如果要自定义 Doskey.exe 如何处理程序并为该程序创建 doskey 宏,则可以创建一个批处理程序,用于修改 Doskey.exe 并启动程序。If you want to customize how Doskey.exe works with a program and create doskey macros for that program, you can create a batch program that modifies Doskey.exe and starts the program.

  • 您可以使用 Doskey.exe 来创建执行一个或多个命令的宏。You can use Doskey.exe to create macros that carry out one or more commands. 下表列出了可用于在定义宏时控制命令操作的特殊字符。The following table lists special characters that you can use to control command operations when you define a macro.

    字符Character 说明Description
    $G$g$G or $g 重定向输出。Redirects output. 使用这两个特殊字符将输出发送到设备或文件而不是屏幕。Use either of these special characters to send output to a device or a file instead of to the screen. 此字符等效于 output () 的重定向符号 >This character is equivalent to the redirection symbol for output (>).
    $G$G$g$g$G$G or $g$g 将输出追加到文件末尾。Appends output to the end of a file. 使用这两个双字符将输出追加到现有文件,而不是替换文件中的数据。Use either of these double characters to append output to an existing file instead of replacing the data in the file. 这些双字符等效于 output () 的追加重定向符号 >>These double characters are equivalent to the append redirection symbol for output (>>).
    $L$l$L or $l 重定向输入。Redirects input. 使用上述任一特殊字符可以从设备或文件而不是键盘读取输入。Use either of these special characters to read input from a device or a file instead of from the keyboard. 此字符等效于输入 () 的重定向符号 <This character is equivalent to the redirection symbol for input (<).
    $B$b$B or $b 将宏输出发送到命令。Sends macro output to a command. 这些特殊字符等效于使用管道 (*These special characters are equivalent to using the pipe ( and *.
    $T$t$T or $t 分隔命令。Separates commands. doskey 命令行上创建宏或类型命令时,可使用以下任一特殊字符分隔命令。Use either of these special characters to separate commands when you create macros or type commands on the doskey command line. 这些特殊字符等效于 & 在命令行上使用与号 () 。These special characters are equivalent to using the ampersand (&) on a command line.
    $$ 指定 () 的货币符号字符 $Specifies the dollar-sign character ($).
    $1 周一至 $9$1 through $9 表示运行宏时要指定的任何命令行信息。Represent any command-line information you want to specify when you run the macro. 使用的特殊 $1 字符 $9 是批处理参数,可让你在每次运行宏时在命令行上使用不同的数据。The special characters $1 through $9 are batch parameters that enable you to use different data on the command line each time you run the macro. $1 Doskey命令中的字符类似于 %1 批处理程序中的字符。The $1 character in a doskey command is similar to the %1 character in a batch program.
    $* 表示键入宏名时要指定的所有命令行信息。Represents all the command-line information that you want to specify when you type the macro name. 特殊字符 $* 是类似于批处理参数的可替换参数 $1 $9 ,其中一个重要区别是:在宏名称后,在命令行上键入的所有内容都将替换为 $* 宏中的。The special character $* is a replaceable parameter that is similar to the batch parameters $1 through $9, with one important difference: everything you type on the command line after the macro name is substituted for the $* in the macro.
  • 若要运行宏,请在命令提示符处键入宏名称,从第一个位置开始。To run a macro, type the macro name at the command prompt, starting at the first position. 如果使用 $* 或任意批处理参数定义了宏 $1 $9 ,请使用空格分隔参数。If the macro was defined with $* or any of the batch parameters $1 through $9, use a space to separate the parameters. 不能从批处理程序运行 doskey 宏。You cannot run a doskey macro from a batch program.

  • 如果始终使用特定命令和特定命令行选项,则可以创建一个与命令同名的宏。If you always use a particular command with specific command-line options, you can create a macro that has the same name as the command. 若要指定是要运行宏还是运行命令,请遵循以下准则:To specify whether you want to run the macro or the command, follow these guidelines:

    • 若要运行此宏,请在命令提示符处键入宏名称。To run the macro, type the macro name at the command prompt. 不要在宏名之前加空格。Do not add a space before the macro name.

    • 若要运行此命令,请在命令提示符处插入一个或多个空格,然后键入命令名称。To run the command, insert one or more spaces at the command prompt, and then type the command name.

示例Examples

/Macros/history命令行选项可用于创建批处理程序以保存宏和命令。The /macros and /history command-line options are useful for creating batch programs to save macros and commands. 例如,若要存储所有当前 doskey 宏,请键入:For example, to store all current doskey macros, type:

doskey /macros > macinit

若要使用存储在 Macinit 中的宏,请键入:To use the macros stored in Macinit, type:

doskey /macrofile=macinit

若要创建一个名为 Tmp.bat 的批处理程序,其中包含最近使用的命令,请键入:To create a batch program named Tmp.bat that contains recently used commands, type:

doskey /history> tmp.bat

若要定义包含多个命令的宏,请使用 $t 分隔命令,如下所示:To define a macro with multiple commands, use $t to separate commands, as follows:

doskey tx=cd temp$tdir/w $*

在前面的示例中,TX 宏将当前目录更改为 Temp,然后以宽显示格式显示目录列表。In the preceding example, the TX macro changes the current directory to Temp and then displays a directory listing in wide display format. $*当你运行 tx 选项时,你可以在宏的末尾使用将其他命令行选项追加到dirYou can use $* at the end of the macro to append other command-line options to dir when you run the tx option.

以下宏对新目录名称使用 batch 参数:The following macro uses a batch parameter for a new directory name:

doskey mc=md $1$tcd $1

宏创建一个新目录,然后从当前目录更改到新目录。The macro creates a new directory and then changes to the new directory from the current directory.

若要使用上述宏创建并更改到名为 书籍的目录,请键入:To use the preceding macro to create and change to a directory named Books, type:

mc books

若要为名为Ftp.exe的程序创建doskey宏,请包括 /exename ,如下所示:To create a doskey macro for a program called Ftp.exe, include /exename as follows:

doskey /exename=ftp.exe go=open 172.27.1.100$tmget *.TXT c:\reports$tbye

若要使用上述宏,请启动 FTP。To use the preceding macro, start FTP. 在 FTP 提示符下,键入:At the FTP prompt, type:

go

FTP 运行 openmget再见 命令。FTP runs the open, mget, and bye commands.

若要创建快速、无条件地格式化磁盘的宏,请键入:To create a macro that quickly and unconditionally formats a disk, type:

doskey qf=format $1 /q /u

若要快速而无条件地格式化驱动器 A 中的磁盘,请键入:To quickly and unconditionally format a disk in drive A, type:

qf a:

若要删除名为 vlist的宏,请键入:To delete a macro called vlist, type:

doskey vlist =

其他参考Additional References