How do I run two commands in one line in Windows CMD?

后端 未结 19 1142
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 00:45

I want to run two commands in a Windows CMD console.

In Linux I would do it like this

touch thisfile ; ls -lstrh

How is it done on

19条回答
  •  梦谈多话
    2020-11-22 01:00

    A quote from the documentation:

    • Source: Microsoft, Windows XP Professional Product Documentation, Command shell overview
    • Also: An A-Z Index of Windows CMD commands

    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.

    • ; or ,
      command1 parameter1;parameter2
      Use to separate command parameters.

提交回复
热议问题