You have two problems: your code being displayed while it runs and your code running in an infinite loop.
1. YOUR CODE IS BEING DISPLAYED
By default, batch displays each line of code that it runs before that line of code is run.
To disable this, put the command @echo off
at the top of your script. echo off
disables this behavior, and the @
prevents that line from being displayed.
2. YOUR CODE IS RUNNING IN AN INFINITE LOOP
Since Your code consists of nothing but the two lines in your question, the only possible reason for your code to be running in an infinite loop is that your script is named tree.bat
.
Your script name is causing an infinite loop because of how CMD runs commands. When you call a command and do not provide the full path to that command, batch first looks in the current directory, and then in all of the directories listed in the %PATH%
variable. Because there is an executable in the current directory called tree
(your script), batch assumes that you are trying to call that and runs your script again, causing an infinite loop.
To stop this behavior, rename your script, making sure not to call it anything that is already a batch keyword (a list of batch keywords can be found here).