Question: In 2003 the workbook would just close. But now the same code is re-opening the workbook. There are some lines afterwards and then the sub ends. When the sub ends, the `workbook_open` event gets fired for the closed workbook, even though there is no code that opens any workbooks. The debugger is almost useless, it is not reproducing the bug if I execute everything step by step, in fact everything works fine when I use the debugger.

I use

`ActiveWorkbook.Close False`

For closing the workbook (from an add-in).

Help much appreciated.

Answer: 
It seems valid for Errno::EIO to be raised here (it simply means the child process has finished and closed the stream), so you should expect that and catch it.

For example, see the selected answer in [Continuously read from STDOUT of external process in Ruby](https://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby) and <http://www.shanison.com/2010/09/11/ptychildexited-exception-and-ptys-exit-status/>

BTW, I did some testing. On Ruby 1.8.7 on Ubuntu 10.04, I don't get a error. With Ruby 1.9.3, I do. With JRuby 1.6.4 on Ubuntu in both 1.8 and 1.9 modes, I don't get an error. On OS X, with 1.8.7, 1.9.2 and 1.9.3, I don't get an error. The behavior is obviously dependent on your Ruby version and platform.
As answered [here](https://stackoverflow.com/a/2976109/4869068) and [here](https://unix.stackexchange.com/a/478969), `EIO` can be avoided by keeping a file descriptor to the pty slave device open in the parent process.

Since `PTY.spawn` closes the slave file descriptor passed to the child process, a simple workaround is to open a new one. For example:

```rb
PTY.spawn("ls") do |r, w, pid|
  r2 = File.open(r.path)

  while IO.select([r], [], [], 1)
    puts r.gets
  end

  r2.close
end

```