Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 612 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I run two commands in one line in Windows CMD?

#11
Well, you have two options: Piping, or just `&`:

DIR /S & START FILE.TXT

Or,

tasklist | find "notepad.exe"

Piping (`|`) is more for taking the output of one command, and putting it into another. And (`&`) is just saying run this, and that.

Reply

#12
One more example: For example, when we use the `gulp` build system, instead of

`gulp` - default > build

`gulp build` - build build-folder

`gulp watch` - start file-watch

`gulp dist` - build dist-folder

We can do that with one line:

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

#13
A number of [processing symbols][1] 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.

@echo off
setlocal enabledelayedexpansion
set count=0
set "count=1" & echo %count% !count!

0 1

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:

set "i=5" & set "arg!i!=MyFile!i!" & call echo path!i!=%temp%\%%arg!i!%%

path5=C:\Users\UserName\AppData\Local\Temp\MyFile5

[1]:

[To see links please register here]

Reply

#14
When you try to use or manipulate variables in one line beware of their content! E.g. a variable like the following

> PATH=C:\Program Files (x86)\somewhere;"C:\Company\Cool Tool";%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;

may lead to a lot of unhand-able trouble if you use it as `%PATH%`

1. The closing parentheses terminate your group statement
2. The double quotes don't allow you to use `%PATH%` to handle the parentheses problem
3. And what will a referenced variable like `%USERPROFILE%` contain?
Reply

#15
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
Reply

#16
**It's simple:** just differentiate them with `&&` signs.
Example:

echo "Hello World" && echo "GoodBye World".


*"Goodbye World" will be printed after "Hello World".*
Reply

#17
Yes there is. It's `&`.

`&&` will execute command 2 when command 1 is complete providing it didn't fail.

`&` will execute regardless.
Reply

#18
A quote from the documentation:

* Source: Microsoft, Windows XP Professional Product Documentation, [*Command shell overview*][1]
* Also: [An A-Z Index of Windows CMD commands](

[To see links please register here]

)

>*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.


[1]:

[To see links please register here]

Reply

#19
Use ``&`` symbol in windows to use command in one line
```
C:\Users\Arshdeep Singh>cd Desktop\PROJECTS\PYTHON\programiz & jupyter notebook
```
like in linux
we use,

```
touch thisfile ; ls -lstrh
```
Reply

#20
With windows 10 you can also use [scriptrunner][1]:

ScriptRunner.exe -appvscript demoA.cmd arg1 arg2 -appvscriptrunnerparameters -wait -timeout=30 -rollbackonerror -appvscript demoB.ps1 arg3 arg4 -appvscriptrunnerparameters -wait -timeout=30 -rollbackonerror

it allows you to start few commands on one line you want you can run them consecutive or without waiting each other, you can put timeouts and rollback on error.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through