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?

#1
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?

Reply

#2
You can use & to run commands one after another. Example: `c:\dir & vim myFile.txt`
Reply

#3
If you want to create a cmd shortcut (for example on your desktop) add /k parameter (/k means keep, /c will close window):

cmd /k echo hello && cd c:\ && cd Windows
Reply

#4
`cmd /c ipconfig /all & Output.txt`

This command execute command and open `Output.txt` file in a single command
Reply

#5
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

[To see links please register here]

and here

[To see links please register here]

). 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:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.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):

[HKEY_CLASSES_ROOT\.dll]
"Content Type"="application/x-msdownload"
@="dllfile"

[HKEY_CLASSES_ROOT\dllfile]
@="Application Extension"

[HKEY_CLASSES_ROOT\dllfile\Shell\RegAsm]
@="Register Assembly"

[HKEY_CLASSES_ROOT\dllfile\Shell\RegAsm\command]
@="cmd /k C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\regasm.exe \"%1\" /codebase \"%1\" & pause & exit"

Now I have a nice right-click menu to register an assembly.
Reply

#6
You can use *call* to overcome the problem of environment variables being evaluated too soon - e.g.

set A=Hello & call echo %A%
Reply

#7
In order to execute two commands at the same time, you must put an & (ampersand) symbol between the two commands. Like so:

color 0a & start chrome.exe


Cheers!
Reply

#8
`&` is the Bash equivalent for `;` ( run commands) and `&&` is the Bash equivalent of `&&` (run commands only when the previous has not caused an error).
Reply

#9
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.
Reply

#10
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:

start /b command1 parameters & command2 parameters

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.

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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