How can I debug a .BAT script?

后端 未结 11 1247
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 09:42

Is there a way to step through a .bat script? The thing is, I have a build script , which calls a lot of other scripts, and I would like to see what is the order in which th

相关标签:
11条回答
  • 2020-11-28 10:11

    Did you try to reroute the result to a file? Like whatever.bat >log.txt

    You have to make sure that in this case every other called script is also logging to the file like >>log.txt

    Also if you put a date /T and time /T in the beginning and in the end of that batch file, you will get the times it was at that point and you can map your script running time and order.

    0 讨论(0)
  • 2020-11-28 10:11

    A quite frequent issue is that a batch script is run by double-clicking its icon. Since the hosting Command Prompt (cmd.exe) instance also terminates as soon as the batch script is finished, it is not possible to read potential output and error messages.

    To read such messages, it is very important that you explicitly open a Command Prompt window, manoeuvre to the applicable working directory and run the batch script by typing its path/name.

    0 讨论(0)
  • 2020-11-28 10:17

    rem out the @ECHO OFF and call your batch file redirectin ALL output to a log file..

    c:> yourbatch.bat (optional parameters) > yourlogfile.txt 2>&1

    found at http://www.robvanderwoude.com/battech_debugging.php

    IT WORKS!! don't forget the 2>&1...

    WIZ

    0 讨论(0)
  • 2020-11-28 10:21

    you can use cmd \k at the end of your script to see the error. it won't close your command prompt after the execution is done

    0 讨论(0)
  • 2020-11-28 10:24

    Or.... Call your main .bat file from another .bat file and output the result to a result file i.e.

    runner.bat > mainresults.txt

    Where runner.bat calls the main .bat file

    You should see all the actions performed in the main .bat file now

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