How to prevent batch window from closing when error occurs?

前端 未结 4 2030
予麋鹿
予麋鹿 2021-02-02 05:53

I\'m trying to write batch script to create a folder if it does not already exist. Following up the online examples, below is my script.

The problem is;

相关标签:
4条回答
  • 2021-02-02 06:34

    You need to pass the /K switch to CMD, or just open a Command Window and run the batch from the command line.

    0 讨论(0)
  • 2021-02-02 06:35

    Press start and type cmd and press enter, you will launch a command prompt.

    Just drag and drop what you need to run (your python script, .exe ...) into the cmd windows, and press enter.

    (You might some time to run the cmd as admin: find the cmd in the start menu, right-click on it, choose run as admin).

    0 讨论(0)
  • 2021-02-02 06:44

    I recorded the screen (bandicam) for when I couldn't quite read the error message, and then I could replay it; I suppose this is mainly helpful if you already have software on your computer.

    0 讨论(0)
  • 2021-02-02 06:48

    You could put this line at the beginning of the batch file:

    if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
    

    What this line does is, the first time you run it, it re-launches itself in a subprocess that doesn't exit after it finishes running the batch file.

    0 讨论(0)
提交回复
热议问题