Good morning everyone,
大家,早安,
i try to write a script to do the following example (all in cmd):
我尝试编写脚本来执行以下示例(全部在cmd中):
- execute command
- wait for the command to be finished
- close the cmd window and open a new one
- execute another command
- exit
等待命令完成
关闭cmd窗口并打开一个新窗口
执行另一个命令
My problem is at point 2 and 3. exit
is not possible because the script is terminated . And with the command start cmd /k <command>
a new cmd instance will be opend and both commands (1 and 4) will be executed at once.
我的问题是在第2点和第3点。退出是不可能的,因为脚本已终止。使用命令start cmd / k
Thx in advance
Thx提前
EDIT: The requested code
编辑:请求的代码
cup chocolatey
exit // Not working
cup all -y
pause
EDIT: The solution
编辑:解决方案
@echo off
cup chocolatey
SCHTASKS /delete /tn "updateAll" /f
SCHTASKS /create /tn "updateAll" /tr "cmd.exe /c \"cup all -y\"" /sc ONCE /ST 00:00 /sd 01/01/1910 /RL HIGHEST
SCHTASKS /run /tn "updateAll"
EXIT
1 个解决方案
#1
@echo off
start "" /w someCommand.exe some parameters
SCHTASKS /create /tn "OnDemand" /tr "cmd.exe /c \" command parameters \"" /sc ONCE /sd 01/01/1910 /st 00:00
SCHTASKS /Run /TN "OnDemand"
exit /b %errorlevel%
This will create "OnDemand" task and will run it through the SCHTASKS. It will start a new instance of the command prompt which will be not depending on already running cmd.exe
这将创建“OnDemand”任务,并将通过SCHTASKS运行它。它将启动命令提示符的新实例,该实例将不依赖于已运行的cmd.exe
#1
@echo off
start "" /w someCommand.exe some parameters
SCHTASKS /create /tn "OnDemand" /tr "cmd.exe /c \" command parameters \"" /sc ONCE /sd 01/01/1910 /st 00:00
SCHTASKS /Run /TN "OnDemand"
exit /b %errorlevel%
This will create "OnDemand" task and will run it through the SCHTASKS. It will start a new instance of the command prompt which will be not depending on already running cmd.exe
这将创建“OnDemand”任务,并将通过SCHTASKS运行它。它将启动命令提示符的新实例,该实例将不依赖于已运行的cmd.exe