Project

General

Profile

Actions

Bug #9944

closed

in ruby for windows in "system" a redirection to append a file works incorrectly

Added by bdimych (Dmitry Bolshakov) over 10 years ago. Updated over 1 year ago.

Status:
Rejected
Assignee:
Target version:
-
ruby -v:
ruby 2.0.0p481 (2014-05-08) [i386-mingw32]
[ruby-core:63169]

Description

c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>C:\Ruby200\bin\ruby.exe -v
ruby 2.0.0p481 (2014-05-08) [i386-mingw32]

c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>( echo first line & echo second line & echo third line ) > test.txt

c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>type test.txt
first line
second line
third line

c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>C:\Ruby200\bin\ruby.exe -e "system 'cmd', '/c', 'echo', 'blabla', :out => ['test.txt', 'a']"

c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>type test.txt
blabla
ne
second line
third line

c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>
c:\Users\bdimych>

ruby writes "blabla" in the beginning instead of appending

windows 7 64

Updated by phasis68 (Heesob Park) over 10 years ago

If this is a Windows specific issue, here is a patch:

diff --git a/process.c b/process.c
index e626542..05bb79c 100644
--- a/process.c
+++ b/process.c
@@ -2767,6 +2767,11 @@ run_exec_open(VALUE ary, struct rb_execarg *sargp, char *errmsg, size_t errmsg_b
                     ERRMSG("dup2");
                     return -1;
                 }
+#ifdef _WIN32
+                if (flags & O_APPEND) {
+                    lseek(fd, 0L, SEEK_END);
+                }
+#endif
                 rb_update_max_fd(fd);
             }
             i++; 

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

  • Description updated (diff)
  • Category set to platform/windows
  • Status changed from Open to Assigned
  • Assignee set to windows
  • Target version set to 2.2.0
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

Yes, it is Windows specific, because O_APPEND is not supported by the system, but implemented in runtime libraries.
And "appending" and "seeking to the end at first" are not same.

This is a known issue, as commented in test/ruby/test_process.rb:test_execopts_redirect,

      if windows?
        # currently telling to child the file modes is not supported.

It is impossible to emulate it completely with multi-process, without the system support.
For example,

$ echo foobar > t; ruby -e 'system("cat", in:["t", "a+"])'

should show "foobar" now including Windows, but it will be empty with your patch.

Let us consider...

Actions #3

Updated by naruse (Yui NARUSE) almost 7 years ago

  • Target version deleted (2.2.0)

Updated by jeremyevans0 (Jeremy Evans) over 1 year ago

  • Status changed from Assigned to Rejected

@headius (Charles Nutter) and I discussed this on the train back from RubyKaigi and determined this is a Windows-specific limitation, not a Ruby bug, and nothing Ruby does can fix the issue in all cases.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0