Active5 months ago
I want to run two commands in a Windows CMD console.
May 22, 2018 Scripts accept all Commands that are available at the command line. Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.
It's important to know that the commands in Windows 10, 8, 7, Vista, and XP are called CMD commands or Command Prompt commands, and the commands in Windows 98/95 and MS-DOS are called DOS commands. We've included all of them in this list to help show changes in commands from operating system to operating system. SECTION A GETTING STARTED. Before we dive into the commands, here are sort of the prelude and how to launch the command prompt; This guide should be good for most of the modern Windows installations – Windows 7, Windows 8, and Windows 10. 286 rows Apr 16, 2019 What is Command Prompt and CMD Commands? Command Prompt, also. A command prompt is an entry point for typing computer commands in the Command Prompt window. By typing commands at the command prompt, you can perform tasks on your computer without using the Windows graphical interface. This tutorial will show you different ways to open a command prompt in Windows 10.
In Linux I would do it like this
How is it done on Windows?
Soviut61.2k3737 gold badges150150 silver badges218218 bronze badges
flybywireflybywire103k175175 gold badges372372 silver badges487487 bronze badges
17 Answers
Like this on all Microsoft OSes since 2000, and still good today:
If you want the second command to execute only if the first exited successfully:
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:
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.
djdanlibdjdanlib14.2k11 gold badge1515 silver badges2424 bronze badges
A quote from the documentation:
- Source: Microsoft, Windows XP Professional Product Documentation, Command shell overview
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.
7,67933 gold badges2323 silver badges3838 bronze badges
&
is the Bash equivalent for ;
( run commands) and &&
is the Bash equivalent of &&
(run commands only when the previous has not caused an error).14.5k1919 gold badges8989 silver badges118118 bronze badges
manojldsmanojlds228k4949 gold badges398398 silver badges377377 bronze badges
You can use & to run commands one after another. Example:
scrappedcolascrappedcolac:dir & vim myFile.txt
9,62511 gold badge2424 silver badges4141 bronze badges
If you want to create a cmd shortcut (for example on your desktop) add /k parameter (/k means keep, /c will close window):
TroodoN-MikeTroodoN-Mike10.3k1111 gold badges4646 silver badges7373 bronze badges
You can use call to overcome the problem of environment variables being evaluated too soon - e.g.
Stephan39.3k55 gold badges3535 silver badges6464 bronze badges
SSiSSi
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:WindowsMicrosoft.NETFrameworkv4.0.30319regasm.exe '%1' /codebase '%1' & pause & exit
This works like a charm -- RegAsm runs on the file and shows its results, then a 'Press any key to continue..' prompt is shown, then the command prompt window closes when a key is pressed.
P.S. For others who might be interested, you can use the following .reg file entries to add a dllfile association to .dll files and then a RegAsm command extension to that (notice the escaped quotes and backslashes):
Now I have a nice right-click menu to register an assembly.
Community♦
SNAFUBARSNAFUBAR
A number of processing symbols can be used when running several commands on the same line, and may lead to processing redirection in some cases, altering output in other case, or just fail. One important case is placing on the same line commands that manipulate variables.
As you see in the above example, when commands using variables are placed on the same line, you must use delayed expansion to update your variable values. If your variable is indexed, use CALL command with %% modifiers to update its value on the same line:
Graham4,2481414 gold badges4444 silver badges6464 bronze badges
sambul35sambul35
cmd /c ipconfig /all & Output.txt
This command execute command and open
Output.txt
file in a single commanddpp.2325dpp.2325
In order to execute two commands at the same time, you must put an & (ampersand) symbol between the two commands. Like so:
Cheers!
PryroTechPryroTech
I try to have two pings in the same window, and it is a serial command on the same line. After finishing the first, run the second command.
The solution was to combine with
start /b
on a Windows 7 command prompt.Start as usual, without
/b
, and launch in a separate window.The command used to launch in the same line is:
Any way, if you wish to parse the output, I don't recommend to use this.I noticed the output is scrambled between the output of the commands.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
sdcxpsdcxp
Well, you have two options: Piping, or just
&
:Or,
Piping (
Peter Mortensen|
) is more for taking the output of one command, and putting it into another. And (&
) is just saying run this, and that. 14.5k1919 gold badges8989 silver badges118118 bronze badges
PyDeverPyDever
No,
cd / && tree && echo %time%
. The time echoed is at when the first command is executed.The piping has some issue, but it is not critical as long as people know how it works.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
notarealnamenotarealname
It's simple: just differentiate them with && signs. Example:
Goodbye World will be printed after Hello World.
Rajan DhanowaRajan Dhanowa
One more example: For example, when we use the
gulp
build system, instead ofgulp
- default > buildgulp build
- build build-foldergulp watch
- start file-watchgulp dist
- build dist-folderWe can do that with one line:
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
Mile MijatovicMile Mijatovic
When you try to use or manipulate variables in one line beware of their content! E.g. a variable like the following
may lead to a lot of unhand-able trouble if you use it as
%PATH%
- The closing parentheses terminate your group statement
- The double quotes don't allow you to use
%PATH%
to handle the parentheses problem - And what will a referenced variable like
%USERPROFILE%
contain?
user6250760
V15I0NV15I0N
Yes there is. It's &.
Naruto shippuden episode 157 subbed. && will execute command 2 when command 1 is complete providing it didn't fail.
& will execute regardless.
هادی کشاورز Hadi Keshavarzهادی کشاورز Hadi Keshavarz
protected by Community♦Sep 24 '17 at 11:49
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged windowsbatch-filecommand-linecmd or ask your own question.
RECOMMENDED: Click here to fix Windows errors and improve PC performance
Majority of Windows users will never need to open Command Prompt as administrator or elevated Command Prompt as many of the commands can be executed without the elevated Command Prompt.
That said, there are some tasks that can only be performed from Command Prompt running with administrator rights, and you get “You may not have permission to perform this operation” or “Access is denied” error when you try to execute certain commands without admin rights.
In Windows 10, there are a bunch of ways to open Command Prompt as administrator or run elevated Command Prompt. You can follow one of the below mentioned methods to launch Command Prompt as administrator in Windows 10.
NOTE: If you’re wondering how to know that the Command Prompt has been launched as administrator, it’s easy. When the Command Prompt is launched with admin rights, “Administrator” text will appear on the titlebar (see the above picture) of the Command Prompt window.
Anyways, below are the methods to open Command Prompt as administrator in Windows 10.
Method 1 of 6
Use shortcut keys to quickly open elevated Command Prompt
This is probably the easiest and fastest method out there to open Command Prompt as administrator.
Step 1: Press the Windows logo key on the keyboard or simply click/tap the Windows logo button on the bottom-left corner of the screen to open the Start.
Step 2: Type CMD in the Start/taskbar search box (search box is automatically selected when you open Start) or in the Run command box, and then simultaneously press Ctrl+Shift+Enter keys.
Step 3: Click the Yes button when you see the User Account Control dialog box. That’s it!
Note: If you are using a non-admin account, you’ll be asked to enter the admin account password in order to open the Command Prompt as administrator.
Method 2 of 6
Use search to open elevated Prompt from Start
Step 1: Open Start by either clicking the Windows logo key on the bottom left corner of the screen or by pressing the Windows logo key on the keyboard.
Step 2: Type Command Prompt or CMD in the search box to see Command Prompt entry in the result, right-click on the Command Prompt, and then click Run as administrator.
Method 3 of 6
Admin Command Prompt from Start menu
Step 1: Open the Start by clicking the Windows logo button on the extreme left on the taskbar (bottom left corner of the screen) or by pressing the Windows logo key on the keyboard.
Step 2: In the Start, click or tap All Apps, click or tap Windows System folder, right-click on Command Prompt and then click or tap Run as administrator.
Click or tap Yes button when you see the User Account Control box or enter the password of the admin account if you’re using the Admin account.
Method 4 of 6
CMD as administrator from File Explorer
Step 1: Open Run command dialog box by simultaneously pressing Windows logo and R keys.
Step 2: In the Run command box, type %windir%System32 and then press Enter key to open System32 folder.
Step 3: Locate the file named cmd.exe, right-click on the same, and then click Run as administrator option.
Click Yes button or enter the admin account password when asked to do so.
Method 5 of 6
Open Command Prompt from Task Manager
This method is useful and works only if you signed into the admin account.
Sep 29, 2018 XLStat 2018 Crack with Keygen. XLStat crack, One of the commonest MS office programs to be used in office setups particularly in Excel. Whilst it comes with a wide range of amazing features, there is no harm in having a few advanced sets of features that enhance the functionality and performance of Excel. Xlstat free. Sep 28, 2019 XLStat 2019 Crack Plus License Key there. XLStat 2019 Crack is a great and very famous software for examination modules for Microsoft Excel. This program provides its functions to the spreadsheet program through toolbars. Apr 25, 2019 XLStat Crack With XLStat 2019.1.3 (Crack) + License Key Premium Version Torrent Download 100% Working It also uses pioneer techniques for data computing. Mar 18, 2019 XLStat 2019 Crack + License Key XLStat 2019.1.2 Crack with more than 200 different statistical tools and features for easy analysis and reformation of your data with MS Excel; It is one of most advance 5 application. And It also uses pioneer techniques for data computing for most precise and accurate results. Further, it includes. Jul 04, 2019 XLStat Crack Full Version With License Key Generator Download. XLStat Crack 2019.2.3.3 Build 59614 is the best and most popular software program which work as.
Step 1: Open Task Manager. To do so, you either right-click on Start button or taskbar and then click Task Manager. Task Manager can also be launched using Ctrl+ Shift+Esc hotkey.
If the Task Manager is launched with fewer details is launched, click More details to open the full version.
Step 2: Once the Task Manager is launched, click File menu.
Step 3: Now, hold down the Ctrl key and then click Run new task open Command Prompt as administrator. In this method, you’ll not see the User Account Control dialog box.
That’s it!
Method 6 of 6
Open Command Prompt window here as administrator
As you likely know, when we hold down the Shift key and right-click on a folder, Open Command Prompt window here option appears in the context menu. If you want to open the Command Prompt as administrator from a folder, you can use this method.
Step 1: Click File menu, hover the mouse cursor over Open Command Prompt to see Open Command Prompt as administrator option. Click on the same option to run Command Prompt as administrator.
That’s all we know. If there is an easier way to open Command Prompt as administrator, do let us know by leaving comments. You can also let us know if any of the above mentioned method is not working for you.
Commands For Command Prompt Windows 10
Tip: You can configure Windows to always open Command Prompt as administrator. Please go through our how to always run Command Prompt as administrator guide for detailed instructions.