Question

I have a problem understanding how I can automatically close a batch file that was started from another batch file.

My first batch file looks like this:

@echo off

:logs
start C:\Users\Kenturrac\Desktop\copy.bat

timeout 2

goto logs

So as you can see there, I start another batch file called "copy.bat" which looks like that:

::set arma path
@set ARMAPATH=C:\Users\Administrator.WIN-B8I65OIU3DJ\Desktop\server\dayz_epoch_1

::set log path
@set LOGPATH=%ARMAPATH%\_LOGS
@set MOVEORCOPY=copy


:: Berechne Zeitstempel
@set DAY=%DATE:~0,2%
@set MONTH=%DATE:~3,2%
@set YEAR=%DATE:~6,4%
@set DATE=%YEAR%_%MONTH%_%DAY%

@set HH=%TIME:~0,2%
@IF "%TIME:~0,1%"==" " (
    set HH=0%TIME:~1,1%
)
@set MIN=%TIME:~3,2%
@set SEC=%TIME:~6,2%
@set TIME=%HH%%MIN%

@IF NOT EXIST "%LOGPATH%\%DATE%_%TIME%\" (
    @set TEMPPATH=%DATE%_-_%TIME%
) ELSE ( 
    @set TEMPPATH=%DATE%_-_%TIME%_%SEC%
)

@set TARGETPATH=%LOGPATH%\%TEMPPATH%\
@echo %TARGETPATH%

Exit /b

The problem is that it doesn't close the additional cmd window it started for the "copy.bat". If I use "call" instead of "start", it will mess up the "temppath" variable.

Was it helpful?

Solution

Assuming the second batch file does something more than setting environment variables to values that will be discarded as the batch file is started in a new process, and if the only concern not to use call instead of start is the protection of the values of the variables in the first process, use setlocal / endlocal instructions in the second batch to avoid the problem of file close and the interference in the values of the variables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top