How to close cmd in batch file

Urlagunta Naga Raju 16MCM0004
start cmd /k 

/k: is compulsory which will execute.

launching many command propmts can be done as below.

start cmd /k Call rc_hub.bat 4444

start cmd /k Call rc_grid1.bat 5555

start cmd /k Call rc_grid1.bat 6666

start cmd /k Call rc_grid1.bat 5570.

I want to know what cmd to be used for closing after launching

Eg: if %a="1234" start cmd /k Call rc_grid1.bat --> This is opening cmd , what cmd needs to give to close ?

wolfrevokcats

Closing multiple instances of cmd is not a very uncommon task. It can arise, for example, when debugging some complex set of batch scripts.

There is one of the ways to do this:
First, give cmd windows unique titles. For example,

start "unique_title" cmd.exe /k ...

Second, when you want to close them, get process ids from tasklist output matching the titles. Then kill those ids with taskkill.

tasklist /v /fo csv | findstr "unique_title"

Here is the full example, the first argument is the title substring to match:

kill_title.cmd

@echo off
set TITLE=unique_title
if not "%~1"=="" set "TITLE=%~1"
for /f "tokens=1,2,* delims=," %%a in ('tasklist /fi "imagename eq cmd.exe" /v /fo csv ^| findstr "%TITLE%"') do (
    rem here we check that the first column is "cmd.exe" ... just in case
    if "%%~a"=="cmd.exe" echo taskkill /pid "%%~b"
)

First check the script output, and if it is ok, remove echo before taskkill.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Start a batch file and close Cmd once it is finished

From Dev

how to close a particular window using BATCH or CMD?

From Dev

How Close task in batch file

From Dev

how to make a batch file close automatically

From Java

How to sleep for five seconds in a batch file/cmd

From Dev

how to create random list in cmd batch file

From Dev

How to pass multiple parameters in CMD to batch file

From Dev

Windows batch: how to write cmd output to a file?

From Dev

how to create random list in cmd batch file

From Dev

How to start a PS script file with a batch/cmd?

From Dev

Writing a Batch file for cmd

From Dev

How to wait for file to close in batch file than proceed for execution

From Dev

batch - how can I close a batch file that was started from another batch file

From Dev

Start cmd /k and then close at the end of another batch

From Dev

Close cmd after launching a server with batch

From Dev

How to write a batch file to open applications and close them if they are already open

From Dev

How to Open and Close Internet Explorer from batch file?

From Dev

How to close batch file if one line writes multiple lines?

From Dev

How to parse a XML file with Command Line (cmd/batch)

From Dev

how not to open a Cmd window when running a batch file

From Dev

How do you make a batch file into a cmd comamnd

From Dev

How to enter text in cmd prompt using batch file

From Dev

How to make a batch file that will run multiple queries in cmd and log them

From Dev

How to convert a windows batch file into a signle line "cmd /c" command?

From Dev

How to run a multi-arguments batch file from a vbscript in CMD?

From Dev

How to open cmd and run a batch file in it in one command

From Dev

How to run copype.cmd for WinPE from Batch File

From Dev

How do turn this Windows CMD command to a Batch File?

From Dev

How to remove new line from text file in for loop (CMD/Batch)

Related Related

  1. 1

    Start a batch file and close Cmd once it is finished

  2. 2

    how to close a particular window using BATCH or CMD?

  3. 3

    How Close task in batch file

  4. 4

    how to make a batch file close automatically

  5. 5

    How to sleep for five seconds in a batch file/cmd

  6. 6

    how to create random list in cmd batch file

  7. 7

    How to pass multiple parameters in CMD to batch file

  8. 8

    Windows batch: how to write cmd output to a file?

  9. 9

    how to create random list in cmd batch file

  10. 10

    How to start a PS script file with a batch/cmd?

  11. 11

    Writing a Batch file for cmd

  12. 12

    How to wait for file to close in batch file than proceed for execution

  13. 13

    batch - how can I close a batch file that was started from another batch file

  14. 14

    Start cmd /k and then close at the end of another batch

  15. 15

    Close cmd after launching a server with batch

  16. 16

    How to write a batch file to open applications and close them if they are already open

  17. 17

    How to Open and Close Internet Explorer from batch file?

  18. 18

    How to close batch file if one line writes multiple lines?

  19. 19

    How to parse a XML file with Command Line (cmd/batch)

  20. 20

    how not to open a Cmd window when running a batch file

  21. 21

    How do you make a batch file into a cmd comamnd

  22. 22

    How to enter text in cmd prompt using batch file

  23. 23

    How to make a batch file that will run multiple queries in cmd and log them

  24. 24

    How to convert a windows batch file into a signle line "cmd /c" command?

  25. 25

    How to run a multi-arguments batch file from a vbscript in CMD?

  26. 26

    How to open cmd and run a batch file in it in one command

  27. 27

    How to run copype.cmd for WinPE from Batch File

  28. 28

    How do turn this Windows CMD command to a Batch File?

  29. 29

    How to remove new line from text file in for loop (CMD/Batch)

HotTag

Archive