1

Good morning everyone,

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

  1. execute command
  2. wait for the command to be finished
  3. close the cmd window and open a new one
  4. execute another command
  5. 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.

Thx in advance

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
6
  • Batch by default waits for one command to finish before starting the next command, unless you've got a call or a start /b going. Show us your code. Commented May 4, 2015 at 8:24
  • the problem is that the first command upgrades chocolatey (packet manager). Afterwards the CMD-Window should be reopend again to further use chocolatey commands. Commented May 4, 2015 at 8:27
  • 1
    you'll SCHTASKS to do this.... Commented May 4, 2015 at 8:33
  • I feel like having chocolatey update itself via a separate script would be the easiest solution. You call that script so that it opens in a separate window, that window closes, and then the rest of your code goes about its business as usual. Commented May 4, 2015 at 8:35
  • chocolatey.github.io/usage.html Commented May 4, 2015 at 8:35

1 Answer 1

3
@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

Sign up to request clarification or add additional context in comments.

2 Comments

thats not the desired result and behavior. With SCHTASKS 2 seperate CMD-Instances will be opend and executed at once, I want the commands to be executed one after another
was my fault, used as you wrote above and modified my command a bit. I will edit my question with the solution. Thx man

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.