# [SOLVED] Batch file: multiple instances of a CMD command.



## billybong001 (Feb 14, 2009)

Hi all,

I would like to simultaneously launch multiple instances of a single CMD command. How do I write a batch file to do so?

Regards,
Nicholas.


----------



## jcgriff2 (Sep 30, 2007)

*Re: Batch file: multiple instances of a CMD command.*



billybong001 said:


> Hi all,
> 
> I would like to simultaneously launch multiple instances of a single CMD command. How do I write a batch file to do so?
> 
> ...



Hi Nicholas - 

For info, you can type *cmd /?* for details on the switches available with cmd.

To answer your question, try *cmd /k* - that will execute the command and then keep running.

Regards. . .

jcgriff2

.


----------



## billybong001 (Feb 14, 2009)

*Re: Batch file: multiple instances of a CMD command.*

I don't think you get the idea. For example, I can launch an instance of command prompt and type

ping www.website.com -t

It will continue the process until I press control C.

However I want now to launch for example, three separate instances of command prompt. How do I do this using a batch file rather than manually starting command prompt and entering the command?

Regards,
Nicholas.


----------



## jcgriff2 (Sep 30, 2007)

*Re: Batch file: multiple instances of a CMD command.*

Enter the commands into a notepad then save it as a BAT file.


----------



## billybong001 (Feb 14, 2009)

*Re: Batch file: multiple instances of a CMD command.*

That is not what I wanted. It simply launches the same command over and over again in one instance of command prompt. I need the same command running in multiple instances.

Regards,
Nicholas.


----------



## jcgriff2 (Sep 30, 2007)

*Re: Batch file: multiple instances of a CMD command.*

try this - copy to bat file an execute it

```
start cmd /k ping www.website.com -t & start ping www.website.com -t & start ping www.website.com -t
```
I should warn you to beware of the 3 windows that will fly out at you.

jcgriff2

.


----------



## billybong001 (Feb 14, 2009)

*Re: Batch file: multiple instances of a CMD command.*

Hmm, running that batch file caused an infinite loop of command prompt windows. Which eventually forced me to reset the computer. Currently, the lines:

start cmd -ping www.website.com
start cmd -ping www.website.com
start cmd -ping www.website.com
pause

Successfully call out 3 windows, but they do not automatically run the ping command.

Regards,
Nicholas.

Edit: the command prompt points to the Desktop instead of it's default (users\username). As a result I am unable to use any system commands.


----------



## jcgriff2 (Sep 30, 2007)

*Re: Batch file: multiple instances of a CMD command.*

Hi - 

I used the command that you provided... I didn't think anything of it. Where did you get it from? I have changed the command to timeout at 5 seconds - after launching the 3 separate windows.

Place these into a Notepad, name w/ BAT file ext and execute it -

```
start cmd /k PING 1.1.1.1 -n 1 -w 5000 >NUL 
start cmd /k PING 1.1.1.1 -n 1 -w 5000 >NUL 
start cmd /k PING 1.1.1.1 -n 1 -w 5000 >NUL
```
`

A screenshot of my system is attached. 4 cmd/DOS screens total.

Regards. . . 

jcgriff2

.


----------



## billybong001 (Feb 14, 2009)

*Re: Batch file: multiple instances of a CMD command.*

Thank you jcgriff2, that was absolutely perfect.

I typed out what I would typically enter into command prompt after Users\nicky9499>
It seems I was missing out the /k tags to make it execute.

Speaking of which, what does the /k and >NUL do?

Regards,
Nicholas.


----------



## jcgriff2 (Sep 30, 2007)

*Re: Batch file: multiple instances of a CMD command.*



billybong001 said:


> Thank you jcgriff2, that was absolutely perfect.
> 
> I typed out what I would typically enter into command prompt after Users\nicky9499>
> It seems I was missing out the /k tags to make it execute.
> ...



Hi Nicholas. . .

I am glad that the "final version" is what you were looking for!

The parm */k* tells the cmd/DOS windows from which the command was executed to stay open

*>NUL* directs the output to go nowhere sort of like ECHO OFF

You can get a full listing of these parms. Copy/paste the following -

```
cmd /? > %temp%\1 & start notepad %temp%\1
```
A notepad will open with the results.

Regards. . .

jcgriff2

.


----------



## emperorksb (Apr 12, 2010)

*Re: Batch file: multiple instances of a CMD command.*

hi guys


may i know wat s the use of that 5000


----------



## jcgriff2 (Sep 30, 2007)

Hi - 


```
[font=lucida console]
start cmd /k PING 1.1.1.1 -n 1 -w 5000 >NUL 
[/font]
```
The *5000* = timeout in milliseconds (5 seconds) to wait for each reply.

You can change it to whatever number you like.

Regards. . .

jcgriff2

.


----------



## emperorksb (Apr 12, 2010)

thanx man


----------



## jcgriff2 (Sep 30, 2007)

You're welcome.

For more info about the ping command, type *ping /?* in the cmd/DOS screen.

Regards. . .

jcgriff2

.


----------



## emperorksb (Apr 12, 2010)

hi jcgriff2

one more help 


every morning i have to restart the 3 servers.. before restart i have to stop some applications in that servers .. after restarting again i have to start those applications ..... can i do that through batch file?
pls help me...



Regards
EmperorKSB


----------

