Repository navigation
Conversation
Without native popen, which is always the case on Windows, system dropped its options with a warning and IO.popen ignored err:. Both now pass a file path (including File::NULL) for out: or err:, and [:child, :out] for err:, to ProcessBuilder. jnr-posix's ProcessMaker doesn't implement redirects, so ProcessBuilder is used directly when there is one. Other options still warn as before. Fixes jruby#10081
d40d463 to
f2a7cdd
Compare
headius
left a comment
There was a problem hiding this comment.
This change is probably fine and ShellLauncher is already a mess, but perhaps we should actually make changes against jnr-posix's ProcessMaker to support redirects? It would make sense for at least some of this logic to live there and not become part of JRuby's public API.
|
Good idea. |
Fixes #10081
Without native popen, which is always the case on Windows,
systemdrops its whole options hash with a warning andIO.popenignoreserr:. So something likesystem(cmd, out: File::NULL, err: File::NULL)still prints everything.This passes the redirects that
ProcessBuildercan express through to it: a file path (or anything withto_path, includingFile::NULL) forout:anderr:onsystem, the same forerr:onIO.popen, anderr: [:child, :out]for both. That follows CRuby'scheck_exec_redirect, which opens a path for fd 1 or 2 as write, create and truncate, and handles[:child, fd]separately: https://github.com/ruby/ruby/blob/67814cf9b0f3a4bad6f7369b0c8e6fc69220de64/process.c#L1907-L1912 and https://github.com/ruby/ruby/blob/67814cf9b0f3a4bad6f7369b0c8e6fc69220de64/process.c#L1929-L1953jnr-posix's
ProcessMakerdoesn't implement redirects (itsredirect*methods just callunimplementedError), so when there is a redirect I build the process withProcessBuilderdirectly and copy the environment fromProcessMaker. Without a redirect nothing changes. A redirect also skips in-process launching, since an in-process script shares our streams. Every other option, and redirects to IO objects, fds or symbols, still warn like before.I added specs for
systemwithout:,err: File::NULLanderr: [:child, :out], and forIO.popenwitherr:. They pass on CRuby 3.4.12, and on JRuby on macOS in interpreter and JIT mode and with-Xnative.popen=false, which takes the same path as Windows. With-Xnative.popen=falsethe new specs fail before this change. Two existingIO.popenspecs that useerr: [:child, :out]also start passing in that mode. They're taggedwindows:, so I left the tags alone for now.This overlaps with #6241, which goes further (
chdir:,in:) but has been open since 2020. I kept this one to what the issue needs.Things I noticed but didn't change:
Process.spawnandexechave the same gap on the non-native path,systemthere also ignoreschdir:andexception:, and an options hash at the end of anIO.popencommand array is still dropped with a "popen3 does not support spawn options in JRuby 1.7" warning.