Rehearsal: Record program output

A relevant ad will be displayed here soon. These ads help pay for my hosting.
Please consider disabling your ad blocker on Pony Foo. These ads help pay for my hosting.
You can support Pony Foo directly through Patreon or via PayPal.

Persist standard input to a file and keep track of timestamps, then simulate real-time program execution.

Ever needed to give a talk on a program and show exactly how the output is going to look like, and such?

Maybe you ditched the idea because your program was a bit on the experimental side, and you were afraid it might break, or you were afraid to type the wrong things into the terminal, and boom. Live coding turns into bloodbath, hundreds die.

I just wrote a little thing that can easily read the standard output of a program, and reproduce it at a later time. This sounds pretty simple business, but having it packaged up in a little script, with a simple API, is pretty important.

Oh, it also respects delays in the original execution, rather than dumping everything at once.

To install it, use npm.

npm i -g rehearsal

Now you can prepare an scenario, suppose you want to give a talk on the awesomeness of grunt-ec2, which makes lots of requests over the network, and does stuff. It would be great, being able to demonstrate its abilities without the need for an internet connection.

You can simply run the command as usual, but pipe its output to rehearsal, saving the scenario to a file on disk.

grunt ec2_list --color | rehearsal > scenario

Note that the command is really executed here, we’re just redirecting its output, so make sure that that doesn’t blow up your repository, or production servers, or anything.

I got back a series of encoded streams, persisted in the scenario file. I had to use the --color argument because chalk won’t produce any color coding, otherwise.


The scenario can be reproduced at any time using the reheasal <scenario> command, as shown in the screenshot below.


If you want to take it up a notch, maybe you’d like to create an alias, and then people wouldn’t really be able to tell that you were faking it.

alias realthing="rehearsal scenario"

Using spaces in the alias name is a bit tricky, but it could be done. By not using an alias, but a function instead.

Liked the article? Subscribe below to get an email when new articles come out! Also, follow @ponyfoo on Twitter and @ponyfoo on Facebook.
One-click unsubscribe, anytime. Learn more.