我想在Windows CMD控制台中运行两个命令。
在Linux中我会这样做
touch thisfile ; ls -lstrh
在Windows上是怎么做的呢?
我想在Windows CMD控制台中运行两个命令。
在Linux中我会这样做
touch thisfile ; ls -lstrh
在Windows上是怎么做的呢?
当前回答
当在同一行上运行多个命令时,可以使用许多处理符号,在某些情况下可能导致处理重定向,在其他情况下可能改变输出,或者导致失败。一个重要的例子是将操作变量的命令放在同一行。
@echo off
setlocal enabledelayedexpansion
set count=0
set "count=1" & echo %count% !count!
0 1
正如您在上面的例子中看到的,当使用变量的命令被放在同一行时,您必须使用延迟展开来更新变量值。如果你的变量被索引了,使用CALL命令和%%修饰符来更新它在同一行的值:
set "i=5" & set "arg!i!=MyFile!i!" & call echo path!i!=%temp%\%%arg!i!%%
path5=C:\Users\UserName\AppData\Local\Temp\MyFile5
其他回答
在windows中使用&符号可在一行中使用命令
C:\Users\Arshdeep Singh>cd Desktop\PROJECTS\PYTHON\programiz & jupyter notebook
比如Linux 我们使用,
touch thisfile ; ls -lstrh
&是Bash中等价的;&&是Bash中的&&(只在前一个没有导致错误时才运行命令)。
很简单:用&&符号区分它们。 例子:
echo "Hello World" && echo "GoodBye World".
“再见世界”将印在“你好世界”之后。
您可以使用&来一个接一个地运行命令。示例:c:\dir & vim myFile.txt
嗯,你有两个选择:管道,或只是&:
DIR /S & START FILE.TXT
Or,
tasklist | find "notepad.exe"
管道(|)主要用于获取一个命令的输出,并将其输入到另一个命令中。(&)表示运行这个和那个。