如何在 Windows CMD 中的一行中运行两个命令? [英] How do I run two commands in one line in Windows CMD?

查看:36
本文介绍了如何在 Windows CMD 中的一行中运行两个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to run two commands in a Windows CMD console.

在 Linux 中我会这样做

In Linux I would do it like this

touch thisfile ; ls -lstrh

它在 Windows 上是如何完成的?

How is it done on Windows?

推荐答案

自 2000 年以来在所有 Microsoft 操作系统上都是这样,今天仍然很好:

Like this on all Microsoft OSes since 2000, and still good today:

dir & echo foo

如果您希望第二个命令仅在第一个成功退出时执行:

If you want the second command to execute only if the first exited successfully:

dir && echo foo

在一行上执行多个命令的单与号 (&) 语法可以追溯到 Windows XP、Windows 2000 和一些早期的 NT 版本.(至少 4.0,根据这里的一位评论者的说法.)

The single ampersand (&) syntax to execute multiple commands on one line goes back to Windows XP, Windows 2000, and some earlier NT versions. (4.0 at least, according to one commenter here.)

在向下滚动此页面时,您会发现很多关于此的其他要点.

There are quite a few other points about this that you'll find scrolling down this page.

历史数据如下,对于那些可能会发现它具有教育意义的人.

Historical data follows, for those who may find it educational.

在此之前,&&在该功能被添加到 Microsoft 命令解释器之前,语法只是 shell 替换 4DOS 的一个功能.

Prior to that, the && syntax was only a feature of the shell replacement 4DOS before that feature was added to the Microsoft command interpreter.

在 Windows 95、98 和 ME 中,您将使用管道字符:

In Windows 95, 98 and ME, you'd use the pipe character instead:

dir | echo foo

在 MS-DOS 5.0 及更高版本中,通过一些早期的 Windows 和 NT 版本的命令解释器,(未记录的)命令分隔符是字符 20 (Ctrl+T),我将在这里用 ^T 表示.

In MS-DOS 5.0 and later, through some earlier Windows and NT versions of the command interpreter, the (undocumented) command separator was character 20 (Ctrl+T) which I'll represent with ^T here.

dir ^T echo foo

这篇关于如何在 Windows CMD 中的一行中运行两个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆