why exit or exit /b in batch file in Windows Terminal The system cannot find the batch label specified - exit #20250

Closed
opened 2026-01-31 07:08:02 +00:00 by claunia · 13 comments
Owner

Originally created by @candrapersada on GitHub (Jul 17, 2023).

why when using Windows Terminal + batch file there is an error when using exit?

The system cannot find the batch label specified - exit

[process exited with code 1 (0x00000001)]
You can now close this terminal with Ctrl+D, or press Enter to restart.

https://ss64.com/nt/exit.html

Originally created by @candrapersada on GitHub (Jul 17, 2023). why when using `Windows Terminal` + `batch file` there is an error when using `exit`? ``` The system cannot find the batch label specified - exit [process exited with code 1 (0x00000001)] You can now close this terminal with Ctrl+D, or press Enter to restart. ``` https://ss64.com/nt/exit.html
claunia added the Resolution-ExternalNeeds-Tag-Fix labels 2026-01-31 07:08:03 +00:00
Author
Owner

@lhecker commented on GitHub (Jul 17, 2023):

Please use the issue template when filing a bug report. It helps us narrow down bugs like this. At a minimum we'd need to know the Windows Terminal version you're using as well as your Windows build number. Please add these two details to your comment above.


Could you provide us with a batch file that reproduces the issue for you?

@lhecker commented on GitHub (Jul 17, 2023): Please use the issue template when filing a bug report. It helps us narrow down bugs like this. At a minimum we'd need to know the Windows Terminal version you're using as well as your Windows build number. Please add these two details to your comment above. --- Could you provide us with a batch file that reproduces the issue for you?
Author
Owner

@candrapersada commented on GitHub (Jul 18, 2023):

@ECHO OFF
ECHO ======================================================================================================================
ECHO.
SET /P URL="[Enter video URL] "
ECHO.
ECHO ======================================================================================================================
ECHO.
yt-dlp -o "Downloads/%%(title)s.%%(ext)s" -i --ignore-config "%URL%"
ECHO.
ECHO ======================================================================================================================
ECHO.
ECHO Done!
PAUSE
EXIT
@candrapersada commented on GitHub (Jul 18, 2023): ``` @ECHO OFF ECHO ====================================================================================================================== ECHO. SET /P URL="[Enter video URL] " ECHO. ECHO ====================================================================================================================== ECHO. yt-dlp -o "Downloads/%%(title)s.%%(ext)s" -i --ignore-config "%URL%" ECHO. ECHO ====================================================================================================================== ECHO. ECHO Done! PAUSE EXIT ```
Author
Owner

@237dmitry commented on GitHub (Jul 18, 2023):

I think you have to set:

  "profiles": {
    "defaults": {
      "closeOnExit": "always",
    }

Screenshot 2023-07-18 102027

@237dmitry commented on GitHub (Jul 18, 2023): I think you have to set: ``` "profiles": { "defaults": { "closeOnExit": "always", } ``` ![Screenshot 2023-07-18 102027](https://github.com/microsoft/terminal/assets/78153320/4a79dce2-c48f-4d9f-b00a-28849ea8b8bb)
Author
Owner

@DHowett commented on GitHub (Jul 18, 2023):

closeOnExit is unrelated to the parsing of batch files. Changing it will not help with this issue.

@DHowett commented on GitHub (Jul 18, 2023): `closeOnExit` is unrelated to the parsing of batch files. Changing it will not help with this issue.
Author
Owner

@237dmitry commented on GitHub (Jul 18, 2023):

is unrelated to the parsing of batch files. Changing it will not help with this issue.

If the batch terminates, the console, tab, or pane must be closed because the process is closed. Or not?

@237dmitry commented on GitHub (Jul 18, 2023): > is unrelated to the parsing of batch files. Changing it will not help with this issue. If the batch terminates, the console, tab, or pane must be closed because the process is closed. Or not?
Author
Owner

@DHowett commented on GitHub (Jul 18, 2023):

If the batch terminates, the console, tab, or pane must be closed because the process is closed.

Well, yes, but the filer is reporting that batch files are failing with a specific error. It isn't necessarily going to solve their batch file parsing problem to have the Terminal window exit immediately. It's just going to hide it. The problem will still be there. 🙂

@DHowett commented on GitHub (Jul 18, 2023): > If the batch terminates, the console, tab, or pane must be closed because the process is closed. Well, yes, but the filer is reporting that _batch files are failing with a specific error._ It isn't necessarily going to solve their _batch file parsing_ problem to have the Terminal window exit immediately. It's just going to hide it. The problem will still be there. 🙂
Author
Owner

@237dmitry commented on GitHub (Jul 18, 2023):

Maybe yt-dlp returns exit code 1.

From documentation

In Windows Command Prompt (cmd.exe), exit will return the return code of the previous command.
@237dmitry commented on GitHub (Jul 18, 2023): Maybe yt-dlp returns exit code `1`. From [documentation](https://learn.microsoft.com/en-us/windows/terminal/customize-settings/profile-advanced) ``` In Windows Command Prompt (cmd.exe), exit will return the return code of the previous command. ```
Author
Owner

@DHowett commented on GitHub (Jul 18, 2023):

The text displayed on the screen clearly indicates that it is a specific error from the batch file parser.

The system cannot find the batch label specified - exit

"The system cannot find the batch label specified" indicates that the system cannot find the batch label that has been specified. 😄

@DHowett commented on GitHub (Jul 18, 2023): The text displayed on the screen clearly indicates that it is a specific error from the batch file parser. > `The system cannot find the batch label specified - exit` "The system cannot find the batch label specified" indicates that the system cannot find the batch label that has been specified. :smile:
Author
Owner

@237dmitry commented on GitHub (Jul 18, 2023):

I tried the same batch (without yt-dlp) and no errors.

But then I set:

"closeOnExit": "never"

Screenshot 2023-07-18 224818

@237dmitry commented on GitHub (Jul 18, 2023): I tried the same batch (without yt-dlp) and no errors. But then I set: ``` "closeOnExit": "never" ``` ![Screenshot 2023-07-18 224818](https://github.com/microsoft/terminal/assets/78153320/a5e584e7-9e8f-4d49-9ef4-95d3bc70740d)
Author
Owner

@lhecker commented on GitHub (Jul 18, 2023):

@candrapersada I've just taken your .bat file and saved it with VS Code (UTF-8, LF) and it works fine. Are you sure that the file you've updated as Markdown matches your local file exactly?

@lhecker commented on GitHub (Jul 18, 2023): @candrapersada I've just taken your .bat file and saved it with VS Code (UTF-8, LF) and it works fine. Are you sure that the file you've updated as Markdown matches your local file _exactly_?
Author
Owner

@zadjii-msft commented on GitHub (Jul 19, 2023):

This is 100% the linefeed/carriage return thing. There's an internal feature request / bug report dating back to at least 20171 about this: MSFT:12268173. I believe we've never touched it, because cmd.exe is dark and full of terrors

/dup https://task.ms/12268173


  1. and this SO post dates back to 2008: https://stackoverflow.com/a/232674/1481137 ↩︎

@zadjii-msft commented on GitHub (Jul 19, 2023): This is 100% the linefeed/carriage return thing. There's an internal feature request / bug report dating back to _at least_ 2017[^1] about this: MSFT:12268173. I believe we've never touched it, because [cmd.exe is dark and full of terrors](https://github.com/microsoft/terminal/blob/main/doc/Niksa.md#cmd) /dup https://task.ms/12268173 [^1]: and this SO post dates back to **2008**: https://stackoverflow.com/a/232674/1481137
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Jul 19, 2023):

Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!

@microsoft-github-policy-service[bot] commented on GitHub (Jul 19, 2023): Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!
Author
Owner

@237dmitry commented on GitHub (Jul 19, 2023):

This is 100% the linefeed/carriage return thing.

The example of batch-script is not full. Or perhaps yt-dlp invoke label syntax. This is error-message of cmd.exe that could not find label :exit. Try and get the same error The system cannot find the batch label specified - exit

@echo off
pause
goto:exit
exit
@237dmitry commented on GitHub (Jul 19, 2023): > This is 100% the linefeed/carriage return thing. The example of batch-script is not full. Or perhaps yt-dlp invoke label syntax. This is error-message of cmd.exe that could not find label `:exit`. Try and get the same error `The system cannot find the batch label specified - exit` ``` @echo off pause goto:exit exit ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20250