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

在Linux中我会这样做

touch thisfile ; ls -lstrh

在Windows上是怎么做的呢?


当前回答

再举一个例子:例如,当我们使用gulp构建系统时,而不是

Gulp -默认>构建

Gulp构建-构建构建文件夹

Gulp watch -开始文件监视

Gulp dist- build dist-folder

我们可以用一行代码来实现:

cd c:\xampp\htdocs\project & gulp & gulp watch

其他回答

So, I was trying to enable the specific task of running RegAsm (register assembly) from a context menu. The issue I had was that the result would flash up and go away before I could read it. So I tried piping to Pause, which does not work when the command fails (as mentioned here Pause command not working in .bat script and here Batch file command PAUSE does not work). So I tried cmd /k but that leaves the window open for more commands (I just want to read the result). So I added a pause followed by exit to the chain, resulting in the following:

cmd /k C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "%1" /codebase \"%1\" &暂停&退出

这就像一个咒语——RegAsm在文件上运行并显示其结果,然后显示“按任意键继续…”提示符,然后当按下一个键时命令提示符窗口关闭。

P.S.对于其他可能感兴趣的人,你可以使用以下.reg文件条目来添加一个dllfile关联到.dll文件,然后再添加一个RegAsm命令扩展名(注意转义的引号和反斜杠):

[HKEY_CLASSES_ROOT\.dll]
"Content Type"="application/x-msdownload"
@="dllfile"

[HKEY_CLASSES_ROOT\dllfile]
@="Application Extension"

[HKEY_CLASSES_ROOT\dllfile\Shell\RegAsm]
@="Register Assembly"

[HKEY_CLASSES_ROOT\dllfile\Shell\RegAsm\command]
@="cmd /k C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\regasm.exe \"%1\" /codebase \"%1\" & pause & exit"

现在我有了一个很好的右击菜单来注册程序集。

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

嗯,你有两个选择:管道,或只是&:

DIR /S & START FILE.TXT

Or,

tasklist | find "notepad.exe"

管道(|)主要用于获取一个命令的输出,并将其输入到另一个命令中。(&)表示运行这个和那个。

在windows 10中,你也可以使用scriprunner:

ScriptRunner.exe -appvscript demoA.cmd arg1 arg2 -appvscriptrunnerparameters -wait -timeout=30 -rollbackonerror -appvscript demoB.ps1 arg3 arg4 -appvscriptrunnerparameters -wait -timeout=30 -rollbackonerror

它允许你在一行上启动几个命令,你可以连续运行它们,也可以不等待彼此,你可以设置超时和错误回滚。

文档中的一段话:

来源:微软,Windows XP专业产品文档,命令shell概述 另外:Windows CMD命令的A-Z索引

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.