jbang: Unable to get any output when running with -c or a java file

Describe the bug I’ve installed jbang through homebrew on my macbook and tried the hello world command + java file and neither worked - got some output, but no “Hello World”.

To Reproduce Steps to reproduce the behavior:

  1. Install and configure jbang on my macbook 😉
  2. Run jbang -c 'println("Hello World")'
  3. Get no “Hello World” output
  4. See nothing

Expected behavior I expected to see Hello World printed in the terminal

JBang version Paste output of jbang version --verbose

[jbang] jbang version 0.101.0
0.101.0
Cache: /Users/avioli/.jbang/cache
Config: /Users/avioli/.jbang
Repository:/Users/avioli/.m2/repository

Additional context Here are the logs of installing jbang, configuring my shell and running a command, then a java file.

Homebrew install logs
~/bin> brew install jbang
==> Fetching dependencies for jbang: openjdk
==> Fetching openjdk
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/19.0.1-1
Already downloaded: /Users/avioli/Library/Caches/Homebrew/downloads/c7246ceb366faabcf9dd032058533f2e54a55b52e0baf1e45630280826b0f013--openjdk-19.0.1-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:0e6b0f8b09b57242adf280ec452d2695d596d3108eadfad78e793e0c9f65d2a7
Already downloaded: /Users/avioli/Library/Caches/Homebrew/downloads/d5f9ba41ea1976b2e173ffbe6c1470a16dc7d6c93bd9e5dc54ef85bf601cfa3a--openjdk--19.0.1.arm64_monterey.bottle.1.tar.gz
==> Fetching jbang
==> Downloading https://ghcr.io/v2/homebrew/core/jbang/manifests/0.101.0
Already downloaded: /Users/avioli/Library/Caches/Homebrew/downloads/f8dbd263aa872ecceec745f48a8e5aab4e0f1c92994fa6402ca44808ab0b31c7--jbang-0.101.0.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/jbang/blobs/sha256:816f2af8b9fbf14749e774c994b3e593e348d9b2ebeaef3efdea556a8a274db1
Already downloaded: /Users/avioli/Library/Caches/Homebrew/downloads/b51db9ee3b731481e839d03cd640a77a50c4efc52c402025b915f93ce0dcb1a7--jbang--0.101.0.all.bottle.tar.gz
==> Installing dependencies for jbang: openjdk
==> Installing jbang dependency: openjdk
==> Pouring openjdk--19.0.1.arm64_monterey.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/openjdk/19.0.1: 639 files, 320.0MB
==> Installing jbang
==> Pouring jbang--0.101.0.all.bottle.tar.gz
🍺  /opt/homebrew/Cellar/jbang/0.101.0: 4 files, 5.5MB
==> Running `brew cleanup jbang`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
JBANG init/config logs
~/> jbang app setup --verbose
[jbang] jbang version 0.101.0
[jbang] Added JBang setup lines /Users/avioli/.bashrc
[jbang] Setting up JBang environment...
Please start a new Shell for changes to take effect
~/> cat ~/.bashrc

# Add JBang to environment
alias j!=jbang
export PATH="$HOME/.jbang/bin:$PATH"
~/> source .bashrc

At this point I tried running jbang -c 'println("Hello World")' and since that didn’t output “Hello World” (you can see what it did output further down) I thought that maybe it didn’t have the right java or something, so I found that I can install any jdk via jbang, so I did install 17:

~> jbang jdk install 17
[jbang] Downloading JDK 17. Be patient, this can take several minutes...
[jbang] Installing JDK 17...
~/> jbang jdk java-env
export PATH="/Users/avioli/.jbang/currentjdk/bin:$PATH"
export JAVA_HOME="/Users/avioli/.jbang/currentjdk"
# Run this command to configure your shell:
# eval $(jbang jdk java-env)
~/> eval $(jbang jdk java-env)
~/> jbang jdk list
Installed JDKs (<=default):
  17 <
JBANG running a command
~/bin> jbang -c 'println("Hello World")'
/Users/avioli/.jbang/currentjdk/bin/jshell --execution=local -J--add-modules=ALL-SYSTEM --startup=DEFAULT --startup=/var/folders/wd/9h7_c41x7sd4r23nr1v_2t7r0000gn/T/jbang_arguments_10951042271280239735055ce5ecdf2748da9a2c477f34b8cae1039d04387dd602b61dd8d6e13cc12555.jsh /Users/avioli/.jbang/cache/stdins/055ce5ecdf2748da9a2c477f34b8cae1039d04387dd602b61dd8d6e13cc12555/055ce5ecdf2748da9a2c477f34b8cae1039d04387dd602b61dd8d6e13cc12555.jsh /var/folders/wd/9h7_c41x7sd4r23nr1v_2t7r0000gn/T/jbang_exit_1625712118947532728055ce5ecdf2748da9a2c477f34b8cae1039d04387dd602b61dd8d6e13cc12555.jsh
~/bin> # --- As you can see there is no Hello World output
~/bin> # --- I copy/pasted the above command directly in my shell and hit return:
~/bin> /Users/avioli/.jbang/currentjdk/bin/jshell --execution=local -J--add-modules=ALL-SYSTEM --startup=DEFAULT --startup=/var/folders/wd/9h7_c41x7sd4r23nr1v_2t7r0000gn/T/jbang_arguments_1095104227128023973505
       5ce5ecdf2748da9a2c477f34b8cae1039d04387dd602b61dd8d6e13cc12555.jsh /Users/avioli/.jbang/cache/stdins/055ce5ecdf2748da9a2c477f34b8cae1039d04387dd602b61dd8d6e13cc12555/055ce5ecdf2748da9a2c477f34b8cae1039d0
       4387dd602b61dd8d6e13cc12555.jsh /var/folders/wd/9h7_c41x7sd4r23nr1v_2t7r0000gn/T/jbang_exit_1625712118947532728055ce5ecdf2748da9a2c477f34b8cae1039d04387dd602b61dd8d6e13cc12555.jsh
WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.vector
Hello World
~/bin> # --- Now it worked
JBANG running a java file
~/bin> jbang init hello.java
[jbang] File initialized. You can now run it with 'jbang hello.java' or edit it using 'jbang edit --open=[editor] hello.java' where [editor] is your editor or IDE, e.g. 'eclipse'
~/bin> jbang --verbose hello.java 
[jbang] jbang version 0.101.0
[jbang] Build required as /Users/avioli/.jbang/cache/jars/hello.java.6fd5eee74ec3af4e2bec2ec00c97dd1409a8d6f7514e1e70c847c3d5f80fc8f2.jar not readable or not found.
[jbang] System Java version detected as 17
[jbang] System Java version matches requested version 17
[jbang] Building jar...
[jbang] Compile: /Users/avioli/.jbang/currentjdk/bin/javac -g -d /Users/avioli/.jbang/cache/jars/hello.java.6fd5eee74ec3af4e2bec2ec00c97dd1409a8d6f7514e1e70c847c3d5f80fc8f2.tmp /Users/avioli/bin/hello.java
[jbang] Deleting folder /Users/avioli/.jbang/cache/jars/hello.java.6fd5eee74ec3af4e2bec2ec00c97dd1409a8d6f7514e1e70c847c3d5f80fc8f2.tmp
[jbang] System Java version matches requested version 17
[jbang] run: /Users/avioli/.jbang/currentjdk/bin/java -classpath /Users/avioli/.jbang/cache/jars/hello.java.6fd5eee74ec3af4e2bec2ec00c97dd1409a8d6f7514e1e70c847c3d5f80fc8f2.jar hello
/Users/avioli/.jbang/currentjdk/bin/java -classpath /Users/avioli/.jbang/cache/jars/hello.java.6fd5eee74ec3af4e2bec2ec00c97dd1409a8d6f7514e1e70c847c3d5f80fc8f2.jar hello
~/bin> # --- As you can see there is no Hello World output
~/bin> # --- I copy/pasted the above "run" command directly into my shell and hit return:
~/bin> /Users/avioli/.jbang/currentjdk/bin/java -classpath /Users/avioli/.jbang/cache/jars/hello.java.6fd5eee74ec3af4e2bec2ec00c97dd1409a8d6f7514e1e70c847c3d5f80fc8f2.jar hello
Hello World
~/bin> # --- Now it worked
OS info
~> uname -a
Darwin Evos-MBP.modem 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64
~> system_profiler SPHardwareDataType | awk '1;/OS Loader/{exit}'
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro18,2
      Chip: Apple M1 Max
      Total Number of Cores: 10 (8 performance and 2 efficiency)
      Memory: 32 GB
      System Firmware Version: 7459.141.1
      OS Loader Version: 7459.141.1
My env

Altough I use kitty terminal and elvish shell, I tried using stock macOS Terminal.app using both ZSH and BASH and getting the exact same output - with both JDK 11 and JDK 17.

ANDROID_SDK_ROOT=/Users/avioli/Library/Android/sdk
COLORTERM=truecolor
COMMAND_MODE=unix2003
EDITOR=vim
HOME=/Users/avioli
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_REPOSITORY=/opt/homebrew
INFOPATH=/opt/homebrew/share/info:
JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
KITTY_INSTALLATION_DIR=/Applications/kitty.app/Contents/Resources/kitty
KITTY_PID=2147
KITTY_WINDOW_ID=1
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LOGNAME=avioli
MANPATH=/opt/homebrew/share/man:/Applications/kitty.app/Contents/Resources/man:
NODENV_SHELL=elvish
PATH=/Users/avioli/bin:/Users/avioli/.jbang/bin:/Users/avioli/.plenv/shims:/Users/avioli/.nodenv/shims:/Users/avioli/.rbenv/shims:/opt/homebrew/opt/php@8.1/sbin:/opt/homebrew/opt/php@8.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/avioli/fvm/default/bin:/Users/avioli/.pub-cache/bin:/Users/avioli/Library/Android/sdk/emulator:/Users/avioli/Library/Android/sdk/platform-tools:/Users/avioli/go/bin:/Users/avioli/.cargo/bin
PLENV_SHELL=elvish
PWD=/Users/avioli
RBENV_SHELL=elvish
SHELL=/opt/homebrew/bin/elvish
SHLVL=1
TERM=xterm-kitty
TERMINFO=/Applications/kitty.app/Contents/Resources/kitty/terminfo
TMPDIR=/var/folders/wd/9h7_c41x7sd4r23nr1v_2t7r0000gn/T/
USER=avioli
WINDOWID=73
XDG_CACHE_HOME=/Users/avioli/.cache
XDG_CONFIG_HOME=/Users/avioli/.config
XDG_DATA_HOME=/Users/avioli/.local/share
XPC_FLAGS=0x0
XPC_SERVICE_NAME=application.net.kovidgoyal.kitty.44480134.44480140
__CFBundleIdentifier=net.kovidgoyal.kitty
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0xF

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (4 by maintainers)

Commits related to this issue

Most upvoted comments

This was a real head scratcher for us. It took us a while to realize that we were obviously not running the same code. But thanks to you both we were able to figure out out, thanks for the help @jqno and @avioli !