Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
fd94edb
fix: enable UTF-8 console output for jbang.{cmd,ps1}
wfouche Dec 5, 2025
70b9129
fix: excludes the Byte Order Mark (BOM)
wfouche Dec 5, 2025
a26eb16
fix: save and restore code page in jbang.ps1
wfouche Dec 6, 2025
2ce4e56
fix: add blank line at end of file
wfouche Dec 6, 2025
3986f12
fix: removed chcp from jbang.cmd
wfouche Dec 6, 2025
11a6da1
fix: enable UTF-8 code page locally in jbang.cmd
wfouche Dec 6, 2025
593e6dd
fix: minor cleanup
wfouche Dec 6, 2025
1ffd4dd
fix: add jbangx.cmd to distribution
wfouche Dec 6, 2025
7586b25
fix: spotless updates
wfouche Dec 6, 2025
78a0d78
fix: exit with errorlevel from jbangx.cmd
wfouche Dec 6, 2025
5b28706
fix: remove leading spaces
wfouche Dec 6, 2025
c20c97a
fix: removed unnecessary backslash
wfouche Dec 6, 2025
f39c7b0
fix: tests are for ASCII chars, not UTF-8
wfouche Dec 6, 2025
c3ab7a1
fix: enable delayed expansion in CMD shell
wfouche Dec 6, 2025
2937ad3
fix: reduced the complexity of test shouldHandleSpecialCharacters
wfouche Dec 6, 2025
e381bda
fix: removed ! character from jshell test
wfouche Dec 6, 2025
144b8ff
fix: remove special characters from comment
wfouche Dec 6, 2025
75ad6b8
fix: revert changes to jbang.cmd
wfouche Dec 7, 2025
ead086b
fix: revert changes to integration tests
wfouche Dec 7, 2025
81fccd5
fix: introduce JBANG_CMD_NO_UTF8 env var
wfouche Dec 7, 2025
8f43d6d
fix: use JBANG_WIN_NO_UTF8 with value "true"
wfouche Dec 7, 2025
c0a192f
fix: use JBANG_WIN_NO_UTF8 with value "true"
wfouche Dec 7, 2025
6029952
fix: corrected typo
wfouche Dec 7, 2025
6615fa6
fix: removed space character
wfouche Dec 7, 2025
8c35e6f
fix: add UTF8 support to jbang on Git-Bash
wfouche Dec 7, 2025
344ce4d
fix: simplified utf8 functionality in jbang.ps1
wfouche Dec 8, 2025
936a71f
fix: document use of environment variable JBANG_WIN_NO_UTF8
wfouche Dec 8, 2025
5a8ff45
fix: updated jbang.sh to set and restore the windows code page (if re…
wfouche Dec 9, 2025
3dc58d7
fix: retrieve $? for a failed exec
wfouche Dec 9, 2025
dd2dc44
fix: only enable UTF-8 if JBANG_WIN_ENABLE_UTF8 is true
wfouche Dec 9, 2025
135c051
fix: only enable UTF-8 if JBANG_WIN_ENABLE_UTF8 is true
wfouche Dec 9, 2025
70bbdcf
fix: updated troubleshooting documentation
wfouche Dec 9, 2025
38ed0b7
fix: simplified utf8 support in jbang
wfouche Dec 9, 2025
bc29cb8
fix: updated formatting in jbang.ps1
wfouche Dec 9, 2025
33b5e7b
fix: removed comment in jbang.ps1
wfouche Dec 9, 2025
2a5855f
fix: use setx to set JBANG_WIN_ENABLE_UTF8
wfouche Dec 9, 2025
497ad5a
fix: explain how to disable UTF8 console support
wfouche Dec 9, 2025
e4d5b63
fix: describe use of the setx command
wfouche Dec 10, 2025
24f4629
fix: env var JBANG_WIN_ENABLE_UTF8 is only set by users
wfouche Dec 10, 2025
7c278fc
fix: add support for cygwin
wfouche Dec 10, 2025
a845d52
fix: renamed env var to JBANG_WIN_UTF8
wfouche Dec 10, 2025
dd408c9
fix: simplified conditional statements
wfouche Dec 10, 2025
740e9f2
fix: comment updates
wfouche Dec 10, 2025
9ace9f7
fix: simplified utf-8 if statement
wfouche Dec 10, 2025
a4a3535
fix: jbang.cmd - restore code page before exiting
wfouche Dec 11, 2025
b5eb749
fix: jbang.ps1 - restore code page before exiting
wfouche Dec 11, 2025
990304f
fix: add open line at end of file
wfouche Dec 11, 2025
cf34982
fix: jbang.sh - restore code page before exiting
wfouche Dec 11, 2025
7cc0069
fix: jbang.sh - use double quotes around $os
wfouche Dec 11, 2025
e34ca80
fix: jbang.sh - updated comment
wfouche Dec 11, 2025
760f364
fix: jbang.cmd - always restore the original code page
wfouche Dec 11, 2025
6daf877
fix: foojay test
wfouche Dec 11, 2025
df6e8db
Revert "fix: foojay test"
wfouche Dec 11, 2025
09b8d5f
foojay test comment
wfouche Dec 11, 2025
2f1c9a2
Revert "foojay test comment"
wfouche Dec 11, 2025
31b74f4
fix: jbang.sh restore code page for cygwin and git-bash on Windows
wfouche Dec 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/troubleshooting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,17 @@ jbang --verbose script.java
**Problem**: Various Windows-specific problems

**Solutions**:

1. **Path length limits**: Use shorter paths, enable long path support
2. **Antivirus interference**: Add JBang directories to exclusions
3. **PowerShell execution policy**: `Set-ExecutionPolicy RemoteSigned`
4. **Line endings**: Ensure scripts use LF, not CRLF
5. **UTF-8 console support**: JBang will automatically enable UTF-8 console support by executing command `chcp.com 65001`. To disable this functionality, create environment variable `JBANG_WIN_UTF8` and set it to `false` and restart the shell session. `JBANG_WIN_UTF8` can be set to `false` from the command-line using the `setx` command:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we document where users actually should put that chcp.com 65001 to make it work for everything not just jbang?

+
[source,bash]
----
setx JBANG_WIN_UTF8 false
----

=== macOS Issues

Expand Down
30 changes: 28 additions & 2 deletions src/main/scripts/jbang
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,22 @@ execute_jbang() {
fi

if [ $err -eq 255 ]; then
eval "exec $output"
if [[ "$os" == "windows" ]] && [[ "$JBANG_WIN_UTF8" != "false" ]]; then
bash -c "$output"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why bash not exec here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the command to return to the curent shell , to be able to restore the code page setting at the end of the script.

eval "exec ..." does not return.

else
# Jbang does not return from here ...
eval "exec $output"
fi
elif [ -n "$output" ]; then
echo "$output"
if [[ "$os" == "windows" ]] && [[ "$JBANG_WIN_UTF8" != "false" ]]; then
chcp.com $_original_cp > /dev/null
fi
exit $err
else
if [[ "$os" == "windows" ]] && [[ "$JBANG_WIN_UTF8" != "false" ]]; then
chcp.com $_original_cp > /dev/null
fi
exit $err
fi
}
Expand Down Expand Up @@ -197,10 +208,20 @@ case "$(uname -m)" in
;;
esac

## Enable UTF-8 code page on Windows unless explicitly disabled
if [[ "$os" == "windows" ]] && [[ "$JBANG_WIN_UTF8" != "false" ]]; then
_original_cp=$(chcp.com | grep -o '[0-9]\+')
chcp.com 65001 > /dev/null
fi

## when using cygwin fall out to just running the bat file.
if [[ $os == windows && -f "$abs_jbang_dir/jbang.cmd" && "$(uname -s)" == CYGWIN* ]]; then
cmd /c "$(cygpath -m "$abs_jbang_dir"/jbang.cmd)" "$@"
exit $?
err=$?
if [[ "$os" == "windows" ]] && [[ "$JBANG_WIN_UTF8" != "false" ]]; then
chcp.com $_original_cp > /dev/null
fi
exit $err
fi

if [[ -z "$JBANG_JDK_VENDOR" ]]; then
Expand Down Expand Up @@ -277,3 +298,8 @@ if [[ -z "$binaryPath" ]]; then
fi

execute_jbang "$@"

## Restore the original Windows code page (if required)
if [[ "$os" == "windows" ]] && [[ "$JBANG_WIN_UTF8" != "false" ]]; then
chcp.com $_original_cp > /dev/null
fi
23 changes: 21 additions & 2 deletions src/main/scripts/jbang.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

rem Set UTF-8 code page unless disabled
if not "%JBANG_WIN_UTF8%" == "false" (
for /f "tokens=2 delims=:" %%G in ('chcp') do (
set /a _original_cp=%%G
)
chcp 65001 > nul
)

rem The Java version to install when it's not installed on the system yet
if "%JBANG_DEFAULT_JAVA_VERSION%"=="" (set javaVersion=17) else (set javaVersion=%JBANG_DEFAULT_JAVA_VERSION%)

Expand Down Expand Up @@ -33,7 +41,11 @@ if "!binaryPath!"=="" if "!jarPath!"=="" (
if !ERRORLEVEL! NEQ 0 ( exit /b %ERRORLEVEL% )
)
call "%JBDIR%\bin\jbang.cmd" %*
exit /b %ERRORLEVEL%
set ERROR=%ERRORLEVEL%
if not "%JBANG_WIN_UTF8%" == "false" (
chcp %_original_cp% > nul
)
exit /b %ERROR%
)

if not "!binaryPath!"=="" goto :run_with_cli
Expand Down Expand Up @@ -129,9 +141,16 @@ if %ERROR% EQU 255 (
:break
del /f /q "%tmpfile%"
%OUTPUT%
exit /b %ERRORLEVEL%
set ERROR=%ERRORLEVEL%
if not "%JBANG_WIN_UTF8%" == "false" (
chcp %_original_cp% > nul
)
exit /b %ERROR%
) else (
type "%tmpfile%"
del /f /q "%tmpfile%"
if not "%JBANG_WIN_UTF8%" == "false" (
chcp %_original_cp% > nul
)
exit /b %ERROR%
)
13 changes: 13 additions & 0 deletions src/main/scripts/jbang.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,18 @@ if (-not $binaryPath) {
}
}

if ($env:JBANG_WIN_UTF8 -ne "false") {
$Original_OutputEncoding = $OutputEncoding
$Original_ConsoleInputEncoding = [Console]::InputEncoding
$Original_ConsoleOutputEncoding = [Console]::OutputEncoding
$OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
}

# Execute jbang
Invoke-JBang -binaryPath $binaryPath -jarPath $jarPath -javaExec $JAVA_EXEC -args $args

if ($env:JBANG_WIN_UTF8 -ne "false") {
$OutputEncoding = $Original_OutputEncoding
[Console]::InputEncoding = $Original_ConsoleInputEncoding
[Console]::OutputEncoding = $Original_ConsoleOutputEncoding
}