我想在Windows CMD控制台中运行两个命令。

在Linux中我会这样做

touch thisfile ; ls -lstrh

在Windows上是怎么做的呢?


当前回答

在windows中使用&符号可在一行中使用命令

C:\Users\Arshdeep Singh>cd Desktop\PROJECTS\PYTHON\programiz & jupyter notebook

比如Linux 我们使用,

touch thisfile ; ls -lstrh

其他回答

&是Bash中等价的;&&是Bash中的&&(只在前一个没有导致错误时才运行命令)。

尝试用这些行创建一个.bat或.cmd文件,使用doskey和$T,相当于&,在一行中执行多个命令行:

touch=echo off $T echo. ^> $* $T dir /B $T echo on

它将创建一个空文件。

例子:

touch myfile

在cmd中,你会得到这样的东西:

但是正如前面提到的,建议使用&操作符从CMD提示符在一行中执行多个命令行。

喜欢=)

在windows中使用&符号可在一行中使用命令

C:\Users\Arshdeep Singh>cd Desktop\PROJECTS\PYTHON\programiz & jupyter notebook

比如Linux 我们使用,

touch thisfile ; ls -lstrh

如果你想创建一个cmd快捷方式(例如在你的桌面上),添加/k参数(/k表示保持,/c将关闭窗口):

cmd /k echo hello && cd c:\ && cd Windows

你可以使用call来克服环境变量被太快求值的问题。

set A=Hello & call echo %A%