我想在Windows CMD控制台中运行两个命令。
在Linux中我会这样做
touch thisfile ; ls -lstrh
在Windows上是怎么做的呢?
我想在Windows CMD控制台中运行两个命令。
在Linux中我会这样做
touch thisfile ; ls -lstrh
在Windows上是怎么做的呢?
当前回答
为了同时执行两个命令,必须在两个命令之间加上&(&)符号。像这样:
color 0a & start chrome.exe
干杯!
其他回答
在windows中使用&符号可在一行中使用命令
C:\Users\Arshdeep Singh>cd Desktop\PROJECTS\PYTHON\programiz & jupyter notebook
比如Linux 我们使用,
touch thisfile ; ls -lstrh
&是Bash中等价的;&&是Bash中的&&(只在前一个没有导致错误时才运行命令)。
我试图创建批处理文件启动提升cmd,并使其运行2个单独的命令。 当我使用&或&&字符时,我遇到了一个问题。例如,这是我的批处理文件中的文本:
powershell.exe -Command "Start-Process cmd \"/k echo hello && call cd C:\ \" -Verb RunAs"
我得到解析错误:
经过几次猜测,我发现,如果你用“&&”这样的引号包围&&,它是有效的:
powershell.exe -Command "Start-Process cmd \"/k echo hello "&&" call cd C:\ \" -Verb RunAs"
结果如下:
也许这能帮到别人:)
很简单:用&&符号区分它们。 例子:
echo "Hello World" && echo "GoodBye World".
“再见世界”将印在“你好世界”之后。
不,cd / && tree && echo %time%。回显的时间是第一个命令执行时的时间。
管道有一些问题,但这并不重要,只要人们知道它是如何工作的。