Run multiple cmd window and execute command parallely - windows

What I need is a batch file when opened, it should execute webpack -w command in 3 different folders in 3 different cmd window
What I tried
start
cd P:\localFolder\FolderA
webpack -w
start
cd P:\localFolder\FolderB
webpack -w
start
cd P:\localFolder\FolderC
webpack -w
This will navigate to first folder and executes the webpack -w command and opens one more command window(without changing to specified directory)

Finally the shorter first
start /d P:\localFolder\FolderA webpack -w
start /d P:\localFolder\FolderB webpack -w
start /d P:\localFolder\FolderC webpack -w
to run asynchronously the command should be passed to start
start cmd /c "cd P:\localFolder\FolderA & webpack -w & pause"
start cmd /c "cd P:\localFolder\FolderB & webpack -w & pause"
start cmd /c "cd P:\localFolder\FolderC & webpack -w & pause"
& is the command delimiter
EDIT after comment and, the first & can be changed to &&, to avoid doing the second command if the first fails
start cmd /c "cd /d P:\localFolder\FolderA && webpack -w & pause"
start cmd /c "cd /d P:\localFolder\FolderB && webpack -w & pause"
start cmd /c "cd /d P:\localFolder\FolderC && webpack -w & pause"
the last & pause is just to see the output after execution
for documentation use autodocumented commands in a cmd
start /?

Related

Change the title in the cmd prompt using batch file

I created a .bat file which executes multiple calls in different command prompt.
#echo off
title Start multiple services
start cmd /k Call mongod
start cmd /k Call elasticsearch
timeout /t 5
start cmd /k Call kibana
cd "C:\New folder\influxdb-1.7.6_windows_amd64\influxdb-1.7.8-1\"
start influxd.exe
timeout /t 10
cd "C:\App\App1\bin"
start cmd /k node www
cd "C:\App\App2\server"
start cmd /k node server.js
cd "C:\App\App3\server"
start cmd /k node server.js
cd "C:\App\App4\server"
start cmd /k node server.js
the issue what I am facing that for App2, App3 and App4. I am getting the same title "node server.js" in the command prompt which is creating confusion. How could I add different names in the title for these. I tried putting TITLE in the command like start cmd /k TITLE App3 node server.js. But that didn't work.
You can do the same by
START /D C:\App\App2\bin "write your title" cmd /k node server.js
For reference check: https://ss64.com/nt/start.html

Start /b command is not completing the command and exit SSH straightaway

I am using ssh to run a bat file which will be running multiple commands in parallel as below:
(
start "" cmd /c "cd "C:/Users/desktop" && python -m command"
start "" cmd /c "cd "C:/Users/desktop" && python -m command"
) | pause >nul
the bat file is able to run however, i requrie the output of the python to be shown in the command window. I have tried to include /b in the command
(
start /b "" cmd /c "cd "C:/Users/desktop" && python -m command"
start /b "" cmd /c "cd "C:/Users/desktop" && python -m command"
) | pause >nul
However, the above does not work. It exited before finishing the run of the python commands.

Use a batch file to automatically start 5 separate cmd prompts, where each cmd prompt points to a different directory and starting the php web server

I hope you can help me out with this issue, which I thought would be quite trivial but is turning out to be quite a bugger.
As mentioned in the subject line this is what I want to accomplish:
Automatically run 5 command prompts, each new command prompt needs to do the following
Change directories to a specific location
start the built in php web server
This is the code I currently have for my .bat file:
start cmd /k
cd "directory 1"
php -S localhost:8081
start cmd /k
cd "directory 02"
php -S localhost:8082
start cmd /k
cd "directory 03"
php -S localhost:8083
etc...
Update (here are the working commands after some tweaking)
start "Dir1" /d "directory1" cmd /k "php -S localhost:8081"
start "Dir2" /d "directory2" cmd /k "php -S localhost:8082"
start "Dir3" /d "directory3" cmd /k "php -S localhost:8083"
start "Dir4" /d "directory4" cmd /k "php -S localhost:8084"
start "Dir5" /d "directory5" cmd /k "php -S localhost:8085"
start "Dir6" /d "directory6" cmd /k "php -S localhost:8086"
Thanks very much.
Cheers,
Tim K
The command has to be on the same line as cmd /k, else you start a new window and execute the next line in the original window. Start has a /d switch to set the working folder for the new process, so you don't need cd:
start "Dir1" /d "directory 1" cmd /k "php -S localhost:8081"
REM etc.
When the folder names and ports are accurate, you can use a for /L loop to simplify things:
for /l %%i in (1,1,5) do start "Dir %%i" /d "directory %%i" cmd /k "php -S localhost:808%%i"

How to run commands on another cmd

I want to run commands on 2 cmds while opening the same file, like if I open a .bat file It opens 2 cmd and they run 2 differents commands (1 each). It's possible to do that?
If I got you right this is what you want to do, note it's a batch file:
#echo off
start cmd /c "echo 1st command && pause"
start cmd /c "echo 2nd command && pause"
Read about cmd here and about start here. The following switches of the cmd command can be considered:
/c: Carries out the command specified by string and then stops.
/k: Carries out the command specified by string and continues.
Instead of using /k I used /c with a pause command to show the concatenation of 2 commands here.
To concate 2 commands use commandA && commandB which is described here at ss64 which is a great site when it comes to batch scripting:
commandA && commandB: Run commandA, if it succeeds then run commandB
As requested another example with cd, dir and pause could look like:
#echo off
start cmd /c "cd C:\Users\ && dir && pause"
start cmd /c "cd C:\ && dir && pause"
It changes the directory, prints the directory list and wait for use input.

How do I run another command in a cmd batch file?

I have this command that i need to run
cd /d C:\leads\ssh & C:\Windows\System32\cmd.exe /E:ON /K C:\Ruby192\bin\setrbvars.bat
this opens the command prompt
but I need to run this command in the prompt
ruby C:\lead\leads.rb
which will fire off a script.....but i have no idea what to add to my bat file to do this
i tried the -f flag to tell it to run the command but no go....any ideas to what to do to make this run
cd /d C:\leads\ssh & C:\Windows\System32\cmd.exe /E:ON /K C:\Ruby192\bin\setrbvars.bat -f ruby C:\lead\leads.rb
pause
Try the following batch file:
#echo off
cd /d C:\leads\ssh
call C:\Ruby192\bin\setrbvars.bat
ruby C:\lead\leads.rb

Resources