Command line interpreter overview

xiaoxiao2021-03-06  24

Command line interpreter overview

The command line interpreter is a separate software program that provides direct communication between the user and the operating system. Non-graphic command line interpreter User interface provides an environment that runs characters-based applications and utilities. By using

MS-DOS

Command Interpreter The Separate Character of Command.com, the command line interpreter executes the program and displays its output on the screen.

Windows

Server Operating System Command Line Interpreter Using Command Interpretation CMD.exe (This program loads the application and guides information between applications) to convert user input to the operating system's understandable form.

You can use the command line interpreter to create and edit the batch file (also known as script) that automatically performs regular tasks. For example, you can automatically manage user accounts or night backups using scripts. You can also run a higher level script in the command line interpreter using the command line version of the Windows Script Host CScript. For more information, see Running a Windows Script Host. The operation is performed by using a batch file, which is more efficient than using the user interface. Batch file accepts all commands available on the command line. For more information on batch files and scripts, see Using a batch file.

You can customize the command prompt window to easily view and enhance the control of the program operation mode. For more information on the custom command prompt window, see Configuring a Command Prompt.

Use the command syntax

The syntax appears in the order in which the command and the parameters must follow. The following xcopy command example shows a variety of syntax text formats:

xcopy

Source [

Destination]

[

/ w]

[

/ P]

[

/ c]

[

/ v]

[

/ q]

[

/ f]

[

/ L]

[

/ g]

[

/ d [

:

MM-DD-YYYY]]]]]]]]]

[

/ u]

[

/ i]

[

/ s

/ e]]

[

/ t]

[

/ K]

[

/ r]

[

/ h]

[{

/ a |

/ m}]

[

/ n]

[

/ o]

[

/ x]

[

/ Exclude:

File1 [

[

File2]] [

[

File3]]]]]

[{

/ y |

/ -y}]

[

/z]

The following table shows how to explain different text formats.

Formatting map

Format Meaning Object Users must provide information Bold users must accurately typure the element omitted (...) to display (...) in the command line, multiple times ([]) optional braces ({}); The option is separated with a vertical line (|). For example: {EVEN | ODD} User must select a Courier font code or program output from the option collection

Use multiple commands and conditions to process symbols

Use the conditional processing symbols to run multiple commands in a single command line or script. When you run multiple commands by conditional processing symbols, the commands that the condition handle the right side of the symbols works in accordance with the execution result of the command symbol left command. For example, you may need to run a new command only if the previous command fails. Alternatively, you may need to run a new command only when the previous command is successful.

You can use the special characters listed in the following table to pass multiple commands.

Character Syndrome Definition & [...] Command1 & Command2 is used to separate multiple commands in a command line. CMD.exe runs the first command and then runs the second command. && [...] Command1 && Command2 is only running the symbol after the command is successful when the commands of the symbols &&. Cmd.exe runs the first command and then runs the second command only when the first command is running successfully. || [...] command1 || COMMAND2 is only running symbols || back command when the command fails in the symbol ||. CMD.exe runs the first command, and then runs the second command only when the first command fails to run successfully (received greater than zero error code). () [...] (Command1 & Command2) is used to group or nest multiple commands. Or, Command1 parameter1; parameter2 is used to separate the command parameters. note

"Symbol (&), pipe symbols (|), and parentheses () are special characters, when they are passed as parameters, must be added to their front and escape characters (^) or quotes. If a command successfully completed the operation, the command returns zero (0) exit code or does not return any exit code. For more information on exiting the code, see the Microsoft Windows Deployment and Resource Toolkit.

Nested command line interpreter

You can nest the command line interpreter in the cmd.exe by open the new cmd.exe instance under the command prompt. By default, each instance of cmd.exe inherits the environment of its father's cmd.exe application. By nested cmd.exe, you can change the local environment without affecting the parent application of cmd.exe. This allows you to retain the original environment of cmd.exe and return to the original environment after terminating nested command line interpreters. However, changes made in nesting command line interpreters will not be saved.

To nested a command line interpreter, type in the command prompt:

cmd

A message similar to the following:

Microsoft (R)

Windows Server 2003 Standard Edition

(TM) (C) Copyright 1985-2002 Microsoft Corp.

To close the nested command line interpreter, type exit.

Use the setLocal and endlocal commands to further change localization in the CMD.exe instance (or in the script). SetLocal creates a local scope and endlocal terminates local scope. The changes made in the SETLOCAL and Endlocal scope will be given, thus keeping the original environment constant. The nesting of these two commands can reach 32. For more information on setLocal and endlocal commands, see SetLocal and endlocal.

Use environment variables with cmd.exe

The cmd.exe command line interpreter environment is defined by determining the variable of the command line interpreter and operating system behavior. Two types of environment variables (systems, and local) can be used to define behaviors of command line interpreter environments or throughout the operating system environment. System environment variable defines the behavior of the global operating system environment. The local environment variable defines the behavior of the current instance environment of CMD.exe.

System environment variables are preset among operating systems and can be used for all

Windows

Server operating system process. Only users with management credentials can change the system variable. These variables are most commonly used for login scripts.

The local environment variable is only valid when logging in to the computer when the target user is logged in when the variable is created. The local variable set in the HKEY_CURRENT_USER configuration unit is only valid for the current user, but they can define the behavior of the global operating system environment.

The table below describes the various types of variables according to priority order:

The system variable found in the HKEY_LOCAL_MACHINE configuration unit is found in the HKEY_CURRENT_USER configuration unit All environment variables set in the autoexec.bat file and the path set in the login script (if any) in the login script. The variables used in the script or batch file are in the command line interpreter, and each instance of cmd.exe inherits its parent application. Therefore, variables in the new cmd.exe environment can be changed without affecting the parent application environment.

The table below

Windows Server Operating System

Systems and local environment variables.

Variable type description

% AllUsersprofile%

Locally returns the location of the "All User" profiles.

% Appdata%

Locally returns the location of the application stores data by default.

% CD%

Locally returns the current directory string.

% Cmdcmdline%

Locally returns the exact command line for starting the current cmd.exe.

% Cmdextversion%

The system returns the version number of the current "command handler extension".

% Computername%

The system returns the name of the computer.

% Comspec%

The system returns the accurate path of the command line interpreter executable program.

% DATE%

The system returns the current date. Use the same format as the DATE / T command. Generate from cmd.exe. For more information on the Date command, see Date.

% Errorlevel%

The system returns the error code of the previous command. An error is usually used in a non-zero value.

% HOMEDRIVE%

The system returns a local workstation driver number connected to the user's home directory. Set based on the main directory value. The user home directory is specified in Local Users and Groups.

% HomePath%

The system returns the full path to the user's home directory. Set based on the main directory value. The user home directory is specified in Local Users and Groups.

% HOMESHARE%

The system returns the network path of the user's shared owner. Set based on the main directory value. The user home directory is specified in Local Users and Groups.

% Logonserver%

Locally returns the name of the domain controller that verifies the current login session.

% Number_of_processors%

The system specifies the number of processors installed on the computer.

% OS%

The system returns the operating system name.

WINDOWS 2000

Show its operating system

Windows_nt

.

% PATH%

The system specifies the search path for executable.

% PATHEXT%

The system returns a list of file extensions that the operating system considers executable file extensions.

% Processor_architecture%

The system returns the chip architecture of the processor. Value: x86 or IA64 (based on Itanium).

% Processor_identfier%

The system returns the processor description.

% Processor_level%

The system returns the model of the processor installed on the computer.

% Processor_revision%

The system returns the version number of the processor.

% PROMPT%

Locally returns a command prompt setting for the current interpreter. Generate by cmd.exe.

% Random%

The system returns any decimal number between 0 and 32767. Generate from cmd.exe.

% SystemDrive%

System returns

Windows Server Operating System

The root directory (ie the system root directory) drive.

% Systemroot%

System returns

Windows Server Operating System

The position of the root directory.

% TEMP%

with

% TMP%

Systems and users returns the default temporary directory for applications available to the currently logged in user. Some applications require TEMP, while other applications require TMP.

% Time%

The system returns the current time. Use the same format as the TIME / T command. Generate from cmd.exe. For more information on the Time command, see TIME.

% UserDomain%

Locally returns the name of the domain containing the user account.

% UserName%

Locally returns the name of the currently logged in user.

% UserProfile% returns the location of the current user's configuration file.

% WINDIR%

The system returns the location of the operating system directory.

Set an environment variable

Use the set command to create, change, delete, or display environment variables. The set command only changes the variables in the current interpreter environment.

To view the variable, type in the command prompt:

Set Variablename

To add a variable, type in the command prompt:

Set variablename = value

To delete a variable, type in the command prompt:

Set variablename =

Most characters can be used as variables, including spaces. If you use special characters <,>, |, & or ^, you must add an escape character (^) or quotation number in front. If you use quotation marks, the quotation marks must be used as the value of the value, because any content behind the alignment will be considered value. Consider the following example:

To create a variable value new & name, type: set varname = new ^ & name To create a variable value "new & name", type: set varname = "new & name" If you type set varname = new & name at the command prompt, you will appear with the following Similar error messages: "'Name' is not internal or external files, nor is it runable or batch files."

Variable names are not case sensitive. However, the variables displayed by the SET display are identical to you. Undenders and lowercase letters can be used in the variable name, which makes the code more readable (for example, username).

note

The maximum size of a single environment variable is 8192 bytes. The size of all environment variables, including variable names and equal numbers), up to 65,536 KB.

Replace environment variable value

To enable variable value replacement in a command line or script, include the variable name in the percent sign (ie,

%

Variablename

%

). Use the percent sign to ensure the CMD.exe reference variable value, not a text comparison. After defining a variable value for the variable name, include the variable name in the percent sign. CMD.exe searches all instances of the variable name, and replaces it with a defined variable value. For example, if you create a script containing different values ​​(for example, usernames), and want to use these values ​​to define the username environment variable for each user, you can use the username included in the percent sign to write code. When you run this script, cmd.exe will replace the% username% with variable values ​​so that the necessary need to manually perform this task for each user. Variable replacement is uncomfortable. Cmd.exe checks the variable once. For more information on variable replacement, see FOR and CALL.

转载请注明原文地址:https://www.9cbs.com/read-81317.html

New Post(0)