Skip to content
Fix Code Error

How do I run two commands in one line in Windows CMD?

March 13, 2021 by Code Error
Posted By: Anonymous

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

In Linux I would do it like this

touch thisfile ; ls -lstrh

How is it done on Windows?

Solution

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

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.

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

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

dir | echo foo

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
Answered By: Anonymous

Related Articles

  • Rails wrong number of arguments error when…
  • Simplest way to create Unix-like continuous pipeline…
  • How do I rotate text in css?
  • What are the undocumented features and limitations…
  • How to install the Raspberry Pi cross compiler on my…
  • What is your most productive shortcut with Vim?
  • 'block in draw' rails 6 routes
  • In Pandas, how do I convert a number column to…
  • Gradle error: Execution failed for task…
  • What is the origin of foo and bar?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Get operating system info
  • org.gradle.api.tasks.TaskExecutionException:…
  • PHP parse/syntax errors; and how to solve them
  • How to echo with different colors in the Windows…
  • Can Windows Containers be hosted on linux?
  • Detect if Visual C++ Redistributable for Visual…
  • data.table vs dplyr: can one do something well the…
  • HTML 5 Favicon - Support?
  • Start redis-server with config file
  • Removing double quotes from variables in batch file…
  • Jetpack Compose and Hilt Conflict
  • Execution failed for task…
  • Error: the entity type requires a primary key
  • What are the calling conventions for UNIX &…
  • How can I find the product GUID of an installed MSI setup?
  • Java Process with Input/Output Stream
  • Memcached vs. Redis?
  • Usage of __slots__?
  • How to turn off ALL conventions in Entity Framework Core 5
  • Setting up and using Meld as your git difftool and mergetool
  • How can I fix MySQL error #1064?
  • Echo a blank (empty) line to the console from a…
  • Homebrew install specific version of formula?
  • Reference — What does this symbol mean in PHP?
  • Javascript Drag and drop for touch devices
  • How to paste yanked text into the Vim command line
  • const commandFolders = readdirSync('./commands');…
  • Select DataFrame rows between two dates
  • Individual click handlers in v-for loop
  • How do I install Java on Mac OSX allowing version switching?
  • Unions Data.Map singletons inside an IO
  • What's the difference between eval, exec, and compile?
  • Virtual Memory Usage from Java under Linux, too much…
  • Is this request generated by EF Core buggy or is it my code?
  • What does do?
  • Python sort_values (inplace=True) but not really?
  • How to Filter Data Array by Week Filter()
  • What are the uses of the exec command in shell scripts?
  • Why am I getting a nil pointer error depending on…
  • Docker compose fails to start a service with an…
  • Heroku "Missing required flag -a --app" error after…
  • Get current date, given a timezone in PHP?
  • What does this symbol mean in JavaScript?
  • How do I make calls to a REST API using C#?
  • Replacing blank values (white space) with NaN in pandas
  • Why does C++ code for testing the Collatz conjecture…
  • How to avoid a System.Runtime.InteropServices.COMException?
  • How does PHP 'foreach' actually work?
  • Issue: C compiler used for C++ in CMake | CMake + git
  • Smart way to truncate long strings
  • The definitive guide to form-based website authentication
  • What are the correct version numbers for C#?
  • What is the GAC in .NET?
  • How to convert CMD to JSON array correctly in Dockerfile?
  • Make: "nothing to be done for target" when invoking…
  • SQL query return data from multiple tables
  • Running shell command and capturing the output
  • How to get $HOME directory of different user in bash script?
  • node.js shell command execution
  • Fix top buttons on scroll of list below
  • First echo missing when using bash -c over SSH
  • Runing vue/cli app under docker simple index.html is opened
  • How can I manually compile a svelte component down…
  • Aurelia import library after library
  • FFmpeg: How to split video efficiently?
  • Difference between variable declaration syntaxes in…
  • Change the location of the ~ directory in a Windows…
  • How to install Intellij IDEA on Ubuntu?
  • C threads corrupting each other
  • Show Console in Windows Application?
  • Blazor Can't Update UI
  • Vertical scroll inside paper-header-panel behaving…
  • Executing class instance method that is in an array…
  • How to build boost as shared libraries for Android
  • Identifying and solving…
  • Job for httpd.service failed because the control…
  • Shell script to set environment variables
  • Callback functions in C++
  • What are the currently supported CSS selectors…
  • How to bind custom event handler from…
  • Ukkonen's suffix tree algorithm in plain English
  • C++ IDE for Linux?
  • Multithreading: waiting for a thread to finish so I…
  • How to retreive a variable in Javascript HTML file…
  • Stored procedure or function expects parameter which…
  • How to call shell commands from Ruby
  • What is a NullReferenceException, and how do I fix it?
  • For-each over an array in JavaScript
  • How can I create a Promise in TypeScript from a union type

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Run Command Prompt Commands

Next Post:

Dealing with “java.lang.OutOfMemoryError: PermGen space” error

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error