Project

General

Profile

Actions

Bug #12467

closed

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

Added by yhara (Yutaka HARA) almost 8 years ago. Updated over 7 years ago.

Status:
Third Party's Issue
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)

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

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

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

Actions

Also available in: Atom PDF

Like0
Like0