bat-Script:执行命令,重新打开cmd并执行另一个命令

时间:2021-11-06 01:08:49

Good morning everyone,

大家,早安,

i try to write a script to do the following example (all in cmd):

我尝试编写脚本来执行以下示例(全部在cmd中):

  1. execute command
  2. wait for the command to be finished
  3. 等待命令完成

  4. close the cmd window and open a new one
  5. 关闭cmd窗口并打开一个新窗口

  6. execute another command
  7. 执行另一个命令

  8. exit

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 将打开一个新的cmd实例,并且将立即执行两个命令(1和4)。

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