From http://stackoverflow.com/questions/7559066/reading-commands-from-stdin-and-executing-each-as-it-is-entered