Skip to content

system ignores out: and err:, and IO.popen ignores err:, on Windows #10081

Open

Description

@sferik

Environment Information

  • JRuby 10.0.8.0 and 10.1.3.0
  • Temurin 21.0.13, on GitHub's windows-latest runners
  • Windows Server 2025

Expected Behavior

require "rbconfig"
ruby = RbConfig.ruby

system(ruby, "-e", "puts :out; warn :err", out: File::NULL, err: File::NULL)
p IO.popen([ruby, "-e", "puts :out; warn :err"], err: File::NULL, &:read)

The system should print nothing, and the IO.popen should print only "out\n", as on CRuby (and on JRuby elsewhere).

Actual Behavior

Both warn and run the command without the redirects. This is from Duel's probe, the same on both versions (https://github.com/sferik/duel-ruby/actions/runs/43611021128/job/132495860699):

warning: system does not support options in JRuby yet: {out: "NUL", err: "NUL"}
SUCCESS: The process with PID 6196 (child process of PID 3320) has been terminated.
SUCCESS: The process with PID 7424 (child process of PID 3320) has been terminated.
SUCCESS: The process with PID 3320 (child process of PID 5216) has been terminated.
warning: unsupported popen option: err
err
"out\n"

The first is a system("taskkill", "/T", "/F", "/PID", pid.to_s, out: File::NULL, err: File::NULL), whose output came through anyway. The second is the IO.popen above.

On Windows, PopenExecutor.nativePopenAvailable is always false, so both take the non-native path. There, Kernel#system drops its options hash with that warning:

private static IRubyObject[] dropLastArgIfOptions(ThreadContext context, final IRubyObject[] args) {
IRubyObject lastArg = args[args.length - 1];
if (lastArg instanceof RubyHash hash) {
if (!hash.isEmpty()) Warn.warn(context, "system does not support options in JRuby yet: " + lastArg);
return Arrays.copyOf(args, args.length - 1);
}
return args;

And IO.popen warns for each option in UNSUPPORTED_SPAWN_OPTIONS (in, out and err among them) and goes on without it:

if (options != null) {
Helpers.checkUnsupportedPopenOptions(context, options);
}

The system half is #6113, which was filed for Linux and turned out to be this same non-native path, and #6241 wires up chdir and a few redirects there but has been open since 2020. I'm filing this because on Windows it's the only path, so every system or IO.popen with a redirect gets it. A file or File::NULL for out: and err:, and err: [:child, :out], look doable with ProcessBuilder's redirectOutput, redirectError and redirectErrorStream, and I think the same would work for IO.popen's err:.

I'm working around it in Duel by running such commands through Open3 and reading their output instead.

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