简体   繁体   中英

How to carry out more than one command in a single line

I want to execute a command on cmd windows

cd document
ren log.txt 1.txt

But I want to execute the command in a single line

example : cd document / ren log.txt 1.txt

This will only run the second command if the first command succeeds:

cd document && ren log.txt 1.txt

To run the two commands separately use

cd document & ren log.txt 1.txt

Take a look and Microsoft's Command Shell Overview , specifically see the section regarding Using multiple commands and conditional processing symbols

Using multiple commands and conditional processing symbols

You can run multiple commands from a single command line or script using conditional processing symbols. When you run multiple commands with conditional processing symbols, the commands to the right of the conditional processing symbol act based upon the results of the command to the left of the conditional processing symbol. For example, you might want to run a command only if the previous command fails. Or, you might want to run a command only if the previous command is successful.

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

command1 & command2

Use to separate multiple commands on one command line. Cmd.exe runs the first command, and then the second command.

command1 && command2

Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully.

command1 || command2

Use to run the command following || only if the command preceding || fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).

(command1 & command2)

Use to group or nest multiple commands.

command1 parameter1;parameter2

or

command1 parameter1,parameter2

Use to separate command parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM