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

在Linux中我会这样做

touch thisfile ; ls -lstrh

在Windows上是怎么做的呢?


当前回答

在windows中,我使用了上述所有解决方案&,&&,但都不起作用 ';'符号终于为我工作了

npm install; npm start

其他回答

文档中的一段话:

来源:微软,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.

不,cd / && tree && echo %time%。回显的时间是第一个命令执行时的时间。

管道有一些问题,但这并不重要,只要人们知道它是如何工作的。

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

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

它将创建一个空文件。

例子:

touch myfile

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

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

喜欢=)

在windows中,我使用了上述所有解决方案&,&&,但都不起作用 ';'符号终于为我工作了

npm install; npm start

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

Gulp -默认>构建

Gulp构建-构建构建文件夹

Gulp watch -开始文件监视

Gulp dist- build dist-folder

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

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