Project

General

Profile

Bug #12467

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

Example: 

 ~~~ruby 


 ~~~ 
 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. 

 ~~~ruby ~~~ 
 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)

Back