Bug #15621
closedsystem({}, ...) breaks nonascii ENV["PATH"] on Windows
Description
Problem¶
It seems that system({}, ...) breaks nonascii ENV["PATH"] after execution.
system(...) isn't affected. Only system(env, ...) is affected.
OS: Windows 7
Ruby: https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.1-1/rubyinstaller-2.6.1-1-x64.exe
chcp: 現在のコード ページ: 932
Expected¶
system({}, ...) doesn't break nonascii ENV["PATH"] environment variable after execution.
Actual¶
Here is the sample code to reproduce this issue.
cat break-env-system.rb
# coding: cp932
ENV["PATH"] = [
  "インストール",
  ENV["PATH"],
].join(File::PATH_SEPARATOR)
env = {}
p ENV["PATH"]
system(env, "echo")
p ENV["PATH"]
It produces the following output:
"インストール;%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\CMake\\bin;C:\\GnuWin32\\bin;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\patch-2.5.9-7-bin\\bin;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Ruby26-x64\\bin"
ECHO は <ON> です。
"?C???X?g?[??;%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\CMake\\bin;C:\\GnuWin32\\bin;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\patch-2.5.9-7-bin\\bin;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Ruby26-x64\\bin"
If system("echo") is used instead of system({}, "echo"), ENV["PATH"] is not broken.
Files
        
           Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
          Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
          
          
        
        
      
      - Status changed from Open to Closed
Starting in Ruby 3.0, it appears ENV["PATH"] is unmodified after the call to system.  In prior versions of Ruby, it was modified by the call to system.  This is probably related to the changes to ENV in Ruby 3.0, which will not be backported to earlier Ruby versions.