-
-
Notifications
You must be signed in to change notification settings - Fork 184
fix: enable UTF-8 console output for jbang.{cmd,ps1,sh} on Windows #2349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fd94edb
70b9129
a26eb16
2ce4e56
3986f12
11a6da1
593e6dd
1ffd4dd
7586b25
78a0d78
5b28706
c20c97a
f39c7b0
c3ab7a1
2937ad3
e381bda
144b8ff
75ad6b8
ead086b
81fccd5
8f43d6d
c0a192f
6029952
6615fa6
8c35e6f
344ce4d
936a71f
5a8ff45
3dc58d7
dd2dc44
135c051
70bbdcf
38ed0b7
bc29cb8
33b5e7b
2a5855f
497ad5a
e4d5b63
24f4629
7c278fc
a845d52
dd408c9
740e9f2
9ace9f7
a4a3535
b5eb749
990304f
cf34982
7cc0069
e34ca80
760f364
6daf877
df6e8db
09b8d5f
2f1c9a2
31b74f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why bash not exec here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
There was a problem hiding this comment.
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?