how to bail out of a bat file

This topic contains 2 replies, has 2 voices, and was last updated by  Don Jones 7 months ago.

  • Author
  • #82429


    I have several powershell script that I use to setup an test environment, to speed things up I put them all in a bat file. Everything is fine as long as each script completes with out error. Right now each script can detect if there is a problem and post an error code, that I can pipe to a file. I can also have the script exit, but the next script in the bat file will run. Does anyone know of a way to make the powershell script exit out of the bat file (so that the next script does not run)?


  • #82430

    Don Jones

    It can't. If you're orchestrating everything with a batch file for some reason, then it's up to the batch file to detect an error code and not run the next thing.

  • #82432

    Don Jones

    Me... I'd have written each "PowerShell script" as a function. Then have one script that just calls the functions. Within each function, if there's a problem, throw an error. That'll raise to the calling script and, if it doesn't Catch the error, make it bomb out.

    Or, I mean, do the same thing but keep it all in PowerShell. Same basic effect. When you call a script, if it throws an error and you don't handle it, you bomb.

    Batch files, yuck.

You must be logged in to reply to this topic.