Project

General

Profile

Bug #12467

Open mode 'a' does not work for Process.spawn on Windows

Added by yhara (Yutaka HARA) over 3 years ago. Updated over 3 years ago.

Status:
Third Party's Issue
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x64-mingw32]
[ruby-core:75872]

Description

Example:

spawn 'ruby -e "p Time.now"', [:out, :err] => ['log.txt', 'a']
sleep 1
spawn 'ruby -e "p Time.now"', [:out, :err] => ['log.txt', 'a']
sleep 1
p File.read('log.txt')

This program looks work correctly at first.

c:\>ruby spawn_bug.rb
"2016-06-07 18:47:25 +0900\n2016-06-07 18:28:17 +0900\n"

However, when I run it again, the log file is truncated like 'w' flag.

c:\>ruby spawn_bug.rb
"2016-06-07 18:47:38 +0900\n2016-06-07 18:28:17 +0900\n"

This is the same if I open the log file manually with File.open.

f = File.open('log.txt', 'a')
spawn 'ruby -e "p Time.now"', [:out, :err] => f
sleep 1
spawn 'ruby -e "p Time.now"', [:out, :err] => f
sleep 1
p File.read('log.txt')

I tried this on Windows 10. (Also confirmed this does not happen on Mac OS X 10.11 + ruby 2.2)

History

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Status changed from Open to Third Party's Issue
  • Description updated (diff)

Windows does not provide append mode, but ruby emulates it.

Also available in: Atom PDF