For development purposes, I want a script that just enters in a folder, executes a command there, and when it finishes or fails, waits for user's input, instead of closing the window.

Is this possible?

This is my current script, it works but when the app fails compiling, it should just throw an error to the console and prompt the user for a new command again, instead of closing as it does now:

cd myApp
ionic serve

You can try to use the set /p command. There is an example:

echo The file Input.txt doesn't exist

set /p answer= Do you want to create it now (Y/N)?

if /i "%answer:~,1%" EQU "Y" start notepad.exe

if /i "%answer:~,1%" EQU "N" exit /b

echo Please type Y for Yes or N for No
  • The CHOICE command is meant for exactly this scenario. – Twisty Impersonator Aug 23 '18 at 11:11

Add pause at the end of your script. It will print a "Press any key to continue . . ." message.

  • nope! The "pause" is there, but when the script fails or I exit from it, the window will close instead of staying there, showing the error and letting me use another command, which is what I want in this case. – Zerok Aug 23 '18 at 8:18
  • 1
    What do you mean "I exit from it"? Kill the script mid execution? That sounds like an issue with your "ionic serve" command.Try using conditionals to evaluate the exit code of your command and proceed from there. Although if it's not hitting the pause after failing I would take a look at how your app handles exiting on error. – Gytis Aug 23 '18 at 8:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.