简体   繁体   English

批处理-如何关闭从另一个批处理文件启动的批处理文件

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

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: 因此,如您所见,我启动了另一个名为“ copy.bat”的批处理文件,如下所示:

::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". 问题在于它不会关闭为“ copy.bat”启动的其他cmd窗口。 If I use "call" instead of "start", it will mess up the "temppath" variable. 如果我使用“ call”而不是“ start”,它将弄乱“ temppath”变量。

假设第二个批处理文件除了将环境变量设置为将在新进程中启动该批处理文件时将被丢弃的值之外,还要做其他事情,并且如果唯一不使用call而不是start是保护变量的值在第一个过程中,在第二个批处理中使用setlocal / endlocal指令,以避免文件关闭和变量值受干扰的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows批处理文件-程序关闭后如何在批处理文件中未启动的命令执行 - Windows batch file - how to execute command after program close that's not started in the batch file 如何使用另一个批处理文件中的变量启动Windows批处理文件 - How to start a windows batch file with variables from another batch file 如何在另一个过程中从另一个批处理文件运行一个批处理文件? - How to run a batch file from another batch file but in a separate process? 批处理文件以打开另一个批处理文件,然后自行关闭 - Batch file to to open another batch file and then close itself 如何在批处理文件中关闭cmd - How to close cmd in batch file 如何使批处理文件等到另一个批处理文件完成执行? - How can I make the batch file wait until another batch file completes execution? 从批处理文件启动的程序在后台启动 - Program started from batch file starts in background 从批处理文件开始的文件夹不是活动窗口 - Folder started from batch file is not active window 如何在当前批处理中调用另一个批处理文件中定义的函数? - How can I call a function that is defined in another batch file, in my current batch? 我可以运行带有隐藏cmd窗口的Windows批处理文件但是看到批处理启动的程序吗? - Can I run a windows batch file with hidden cmd window but see the programs started by the batch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM