# Sending irb session to a file in windows

**URL:** <https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576>\
**Category:** Ruby\
**Created:** [April 10, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576 "2007-04-10T17:40:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 10, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576/1 "2007-04-10T17:40:29Z")

</div>

I’m looking to send an irb session to a file. How do people do this on  
Windows?

Andy

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 10, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576/2 "2007-04-10T19:38:46Z")

</div>

On Apr 10, 2007, at 10:40 AM, removed\_email\_address@domain.invalid wrote:

> I’m looking to send an irb session to a file. How do people do this on  
> Windows?

Here’s what you need:

[http://blog.bleything.net/2006/10/21/shell-style-history-for-irb](http://blog.bleything.net/2006/10/21/shell-style-history-for-irb)

James Edward G. II

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 11, 2007, 5:05am UTC](https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576/3 "2007-04-11T05:05:41Z")

</div>

Thanks, James, this is useful, although it appears that it only  
retains the history of commands I enter, without the irb output  
(return values, errors, etc). I’m surprised there’s no way to send all  
of an irb session (input and output) to a file – if I’m still missing  
something, please someone let me know.

For what I want to do (mostly, I just want to pull out snippets from  
an irb session to describe code behavior), what works best for me so  
far is to put the command prompt in QuickEdit Mode and manually copy  
out sections to the clipboard. (I went a long, frustrating time  
without knowing about this – to turn it on, click the mini-command  
prompt on the upper left of the command prompt window and adjust  
defaults or properties.)

Andy

On Apr 10, 1:38 pm, James Edward G. II [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 11, 2007, 7:21am UTC](https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576/4 "2007-04-11T07:21:50Z")

</div>

On Wed, Apr 11, 2007, andy eggers wrote:

> Thanks, James, this is useful, although it appears that it only  
> retains the history of commands I enter, without the irb output  
> (return values, errors, etc). I’m surprised there’s no way to send all  
> of an irb session (input and output) to a file – if I’m still missing  
> something, please someone let me know.

As far as I know (and I’m definitely open to the possibility that I’m  
wrong here) that’s not really possible outside of windows, either. You  
can capture the output, but getting both the input and output would be  
tricky.

I think your best bet is to just copy/paste the sections as you describe  
below. That’s what I’d be doing on OSX to accomplish the same thing.

An alternative would be to look at the history stuff James pointed you  
at, and edit the part that writes history out to a file to also exec  
each line and put its output in the file. My guess is that would get  
you most of the way there.

Either way, please share what you figure out 🙂

Ben

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 11, 2007, 7:46am UTC](https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576/5 "2007-04-11T07:46:52Z")

</div>

On Wed, Apr 11, 2007 at 02:21:09PM +0900, Ben B. wrote:

> tricky.  
> It’s easy in Linux:

$ script foo.txt  
$ irb  
irb\>  
…  
irb\> exit  
$ exit  
$ cat foo.txt

Technically that only captures the output, but since the output includes  
the  
keystrokes you typed echoed back, that’s what you see on the screen.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 11, 2007, 5:14pm UTC](https://www.ruby-forum.com/t/sending-irb-session-to-a-file-in-windows/91576/6 "2007-04-11T17:14:12Z")

</div>

On Wed, Apr 11, 2007, Brian C. wrote:

> It’s easy in Linux:
> 
> $ script foo.txt

oh DUH. I always forget about script. Thanks for reminding me.

Ben
