Skip to content

JRuby stderr stream redirected with standard ">" redirect #58

Open

Description

@adamsnd

Environment Information

  • JRuby 9.3.15, 9.4.12.1, 10.0.1.0 on - all versions exhibited same behaviors
  • Ruby tests on Ruby 2.6.10
  • Win11Pro 26100.4652

Code:
bugtest.rb containing only these two lines:

puts "stdout"
$stderr.puts "stderr"

Expected Behavior
Command line redirect ">" should redirect stdout stream but not stderr stream. stderr stream should remain writing to console unless stderr-specific redirect used (e.g. "2>"). Ruby 2.6.10 performs as expected:

> ruby bugtest.rb
stdout
stderr
> ruby bugtest.rb > bugtest.txt
stderr
> cat .\bugtest.txt
stdout

Actual Behavior
JRuby redirects both streams to file (removed --enable-native-access=org.jruby.dist warnings from output):

> jruby bugtest.rb
stdout
stderr
> jruby bugtest.rb > bugtestjruby.txt
> cat bugtestjruby.txt
stdout
stderr

Activity

  1. headius commented on Jul 31, 2025

    @headius
    Member

    This is quite surprising. I would have expected someone to have reported this issue a long time ago. Could you run jruby --environment and provide the output?

    removed --enable-native-access=org.jruby.dist warnings

    This concerns me a bit. Running jruby in a normal way you should not see those warnings, because we pass that flag for you. Perhaps you are running jruby other than through our normal launcher executable? If you are using that standard executable, it could be missing appropriate flags to enable certain IO access we need.

    Windows support in JRuby has tended to lag behind a bit when it comes to integrating with the native IO and subprocess systems. It still seems more broken than I would expect it to be. I have no theories yet as to why stdout and stderr would be combined like this.

  2. adamsnd commented on Jul 31, 2025

    @adamsnd
    Author

    Java version in case that makes a difference:

    > java -version
    java version "1.8.0_461"
    Java(TM) SE Runtime Environment (build 1.8.0_461-b11)
    Java HotSpot(TM) Client VM (build 25.461-b11, mixed mode, sharing)
    

    Same results observed upon switching to OpenJDK 24:

    > java -version
    openjdk version "24" 2025-03-18
    OpenJDK Runtime Environment (build 24+36-3646)
    OpenJDK 64-Bit Server VM (build 24+36-3646, mixed mode, sharing)
    

    mockup program execution full output:

    Using JRuby 9.3.15 via path set in ENV:

    > jruby bugtest.rb
    WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
    WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by org.jruby.util.StringSupport (file:/c:/jruby-9.3.15.0/lib/jruby.jar)
    WARNING: Please consider reporting this to the maintainers of class org.jruby.util.StringSupport
    WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
    WARNING: A restricted method in java.lang.System has been called
    WARNING: java.lang.System::load has been called by com.kenai.jffi.internal.StubLoader in module org.jruby.dist (file:/c:/jruby-9.3.15.0/lib/jruby.jar)
    WARNING: Use --enable-native-access=org.jruby.dist to avoid a warning for callers in this module
    WARNING: Restricted methods will be blocked in a future release unless native access is enabled
    
    stdout
    stderr
    

    Using JRuby 10.0.1.0:

    > C:\jruby-10.0.1.0\bin\jruby.bat .\bugtest.rb
    WARNING: A restricted method in java.lang.System has been called
    WARNING: java.lang.System::load has been called by com.kenai.jffi.internal.StubLoader in module org.jruby.dist (file:/C:/jruby-10.0.1.0/lib/jruby.jar)
    WARNING: Use --enable-native-access=org.jruby.dist to avoid a warning for callers in this module
    WARNING: Restricted methods will be blocked in a future release unless native access is enabled
    
    stdout
    stderr
    

    jruby --environment

    I don't see --environment listed as an option on https://github.com/jruby/jruby/wiki/JRubyCommandLineParameters

    Did you mean for me to run jruby --properties? I can paste and link that.
    JRuby 9.3.15:

    > C:\jruby-9.3.15.0\bin\jruby.bat --environment
    WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
    WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by org.jruby.util.StringSupport (file:/C:/jruby-9.3.15.0/lib/jruby.jar)
    WARNING: Please consider reporting this to the maintainers of class org.jruby.util.StringSupport
    WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
    jruby: unknown option --environment
    

    JRuby 10.0.1.0:

    > C:\jruby-10.0.1.0\bin\jruby.bat --environment
    jruby: unknown option --environment
    
  3. headius commented on Jul 31, 2025

    @headius
    Member

    The fact that the environment flag doesn't exist shows me how out of date the windows executable is. I'll try to think through some options for improving that situation.

  4. enebo commented on Jul 31, 2025

    @enebo
    Member

    I am wondering what is going on. I am on windows 10 but this all works for me:

    enebo@GODBOX3 C:\Users\enebo
    > jruby b.rb
    stdout
    stderr
    
    enebo@GODBOX3 C:\Users\enebo
    > jruby b.rb > a.txrt
    stderr
    
    enebo@GODBOX3 C:\Users\enebo
    > type a.txrt
    stdout
    
    enebo@GODBOX3 C:\Users\enebo
    > jruby -v
    jruby 10.0.1.0 (3.4.2) 2025-07-17 0f10d1dfdf Java HotSpot(TM) 64-Bit Server VM 21.0.6+8-LTS-188 on 21.0.6+8-LTS-188 +indy +jit [x86_64-mswin32]
    

    Are you using CMD or PS? The warnings do not happen for me and I am seeing separation of stdout and stderr. I half makes me think the wrong jruby.jar is picked up. Can you make sure with jruby -v that it is printing out the right version?

  5. adamsnd commented on Jul 31, 2025

    @adamsnd
    Author

    Both CMD and Powershell give the same responses to jruby --environment and the stdout/stderr redirect test with JRuby 10.0.1.0 and OpenJDK 24.

    After changing path ENV from JRuby 9.3 to C:\jruby-10.0.1.0\bin:

    >jruby -v
    jruby 10.0.1.0 (3.4.2) 2025-07-17 0f10d1dfdf OpenJDK 64-Bit Server VM 24+36-3646 on 24+36-3646 +indy +jit [x86_64-mswin32]
    
  6. headius commented on Oct 24, 2025

    @headius
    Member

    jruby/jruby#9038 adds several manifest entries to open packages and allow native access, which may mitigate this somewhat. However I believe this is mostly an issue with the native launcher on Windows not passing the appropriate flags. I'm going to move the issue there and we will address it in the launcher.

    See #57 for a similar issue.

  7. transferred this issue fromjruby/jrubyon Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions