how to close these separate cmd windows after they are done

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

how to close these separate cmd windows after they are done

#1 Post by goodywp » 19 Oct 2017 14:57

I have a code like this below:

Code: Select all

    
@echo off

cd C:\auto_pkg_build\Scripts\scheme_replace\pkg_data\temp
if exist data1.txt (
   start cmd /k call C:\auto_pkg_build\Scripts\scheme_replace\echo_data1.cmd
   
)


cd C:\auto_pkg_build\Scripts\scheme_replace\pkg_data\temp
if exist data2.txt (
   start cmd /k call C:\auto_pkg_build\Scripts\scheme_replace\echo_data3.cmd
   
)


cd C:\auto_pkg_build\Scripts\scheme_replace\pkg_data\temp
if exist data3.txt (
   start cmd /k call C:\auto_pkg_build\Scripts\scheme_replace\echo_data2.cmd
   
)



cd C:\auto_pkg_build\Scripts\scheme_replace\pkg_data\temp
if exist data4.txt (
   start cmd /k call C:\auto_pkg_build\Scripts\scheme_replace\echo_data4.cmd
   
)


cd C:\auto_pkg_build\Scripts\scheme_replace\pkg_data\temp
if exist data5.txt (
   start cmd /k call C:\auto_pkg_build\Scripts\scheme_replace\echo_data5.cmd

)


The above code run in the main cmd windows and shall pop up 5 separate windows.

Now my questions will be how to close these 5 separate windows automatically after it is done.

Any suggestion shall be welcome.

Thanks

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: how to close these separate cmd windows after they are done

#2 Post by Squashman » 19 Oct 2017 15:43

change

Code: Select all

start cmd /k 

to

Code: Select all

start cmd /c 


Pretty sure you do not need each of the CALL commands in their either.

Why are you doing a change directory 5 times to the same directory? That makes no sense at all.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: how to close these separate cmd windows after they are done

#3 Post by Aacini » 19 Oct 2017 18:51

This is the way I would do it:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Define the order of commands vs. files
set "i=0"
for %%i in (1 3 2 4 5) do (
   set /A i+=1
   set "proc[!i!]=%%i"
)

rem Process all files
cd C:\auto_pkg_build\Scripts\scheme_replace
for /L %%i in (1,1,5) do (
   if exist pkg_data\temp\data%%i.txt (
      call echo_data!proc[%%i]!.cmd
   )
)

Antonio

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: how to close these separate cmd windows after they are done

#4 Post by goodywp » 20 Oct 2017 08:20

Thanks so much for both Squashman and Antonio for you simple and clear advice!

I made the change based upon your suggestion and clean up the code and works perfectly!

I also like Antonio's code for more beauty....

:D

Post Reply