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

查看:101
本文介绍了如何在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.

在此之前,&&语法只是将外壳替换4DOS的功能添加到Microsoft命令解释器之前.

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天全站免登陆