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

后端 未结 19 1109
伪装坚强ぢ
伪装坚强ぢ 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:02

    A number of processing symbols can be used when running several commands on the same line, and may lead to processing redirection in some cases, altering output in other case, or just fail. One important case is placing on the same line commands that manipulate variables.

    @echo off
    setlocal enabledelayedexpansion
    set count=0
    set "count=1" & echo %count% !count!
    
    0 1
    

    As you see in the above example, when commands using variables are placed on the same line, you must use delayed expansion to update your variable values. If your variable is indexed, use CALL command with %% modifiers to update its value on the same line:

    set "i=5" & set "arg!i!=MyFile!i!" & call echo path!i!=%temp%\%%arg!i!%%
    
    path5=C:\Users\UserName\AppData\Local\Temp\MyFile5
    

提交回复
热议问题