How to stream output of system process in Ruby rake task?

Often time, I use Rake to manage a number of tasks I use often, but I can’t remember the command. It’s part of building tools for yourself to make yourself more productive.

Sometimes, you use rake tasks to run servers, like so:

desc "Start the server"
task :start do
  puts `node app.js`

However, that doesn’t work. The child process blocks, and won’t return until the server exits, so that means `puts` never gets a return, and hence never executes. In addition, stdout of the child process running node isn’t connected to the stdout of the parent process running rake. Therefore, you won’t see any output from the server.

Finally, being fed up with the situation, I started looking around on google and stackoverflow, and it’s kind of an elusive question. But I finally have it. It looks like this:

desc "Start the server"
task :start do
  IO.popen("node app.js") { |f| f.each { puts line } }

As long as `node app.js` continuously flushes its stdout, we’ll get its output sent to the rake’s stdout. Yay. One less annoying thing to deal with.

[1] Reference:

Dalton’s point

Recently, Dalton Caldwell posted an Open Letter to Mark Zuckerburg. I was surprised and disappointed by this top level comment and others on Hacker News:

I don’t understand what you think Facebook did wrong. They intend to enter this new space, using their technology and their people. As a courtesy they offered to hire you / throw a lot of money at you. What would you have had them do instead? Not compete with you, because you’re a precious snow flake? Acquire you and treat you like a prima donna, giving you your own team and allowing you to take your own technical direction? – tjlc

I don’t get it either. Last week this guy wanted to make some sort of paid Open Twitter competitor. This week he’s mad at Facebook for offering to acquire his company rather than simply build a first party feature! – temphn

Then the rest of the thread were people arguing over the more granular points about hard-ball tactics. Or about whether it was kosher to invite someone to a meeting and then change the topic of discussion. Or whether a company has a right to do whatever they please with their technology.

It’s as if many readers read one part of the article and it offended some resemblance of ‘sensibility’ in them that they had to click the back button and start ranting about things that have nothing to do with the main point, and others take the bait to feed the trolls.

His open letter to Mark is not about being acu-hired at all, nor is it at all a public complaint what Facebook did, or any of the topics mentioned above. For a while now, the main thesis of his recent blog posts is what he calls an audacious idea:

Social media platforms should not be ad-supported.

Or, if you like it in his own words:

“My thesis is that if you purport to be a platform, your business model needs to reflect your platform-ness. Because if you instead have an ad business model, and you’re not making enough money, you can end up slaughtering your ecosystem.” – Dalton Caldwell

This blog post is a continuation of that theme. The TD; DR version of the open letter is:

Facebook employees are doing asshole things to 3rd party developers[1], even though Facebook calls itself a social media platform[2], not because they’re bad people, but due to bad incentives[3] caused by a search for ad-revenue[4].

[1] “Mark, I know for a fact that my experience was not an isolated incident. Several other startup founders & Facebook employees have told me that what I experienced was part of a systematic M&A “formula”. Your team doesn’t seem to understand that being “good negotiators” vs implying that you will destroy someone’s business built on your “open platform” are not the same thing.”

[2] “Mark, based on everything I know about you, I think you get all of this. It’s why you launched FB platform to begin with. Do remember how you used to always refer to Facebook as a “social utility”?

[3] “I don’t think you or your employees are bad people. I just think you constructed a business that has financial motivations that are not in-line with users & developers.” – Dalton

[4] “your “platform developer relations” executive made no attempt to defend my position. Rather, he explained that he was recently given ownership of App Center, and that because of new ad units they were building, he was now responsible for over $1B/year in ad revenue. The execs in the room made clear that the success of my product would be an impediment to your ad revenue financial goals,” – Dalton

In fact, I’d venture to say that he’s not so much mad at Facebook, or even really caring that Mark Zuckerberg reads it or not. It’s like if you had concerns about the direction education in America, you’d write an op ed piece that is creatively written as a letter that starts with “Dear President Obama”. Of course, you don’t actually expect President Obama to read it, but you do expect Americans that read it to understand your concern for the status of education in America and address your main thesis.

For Dalton, I suspect it’s another piece of proof for him that he’s on the right track about how social media platforms shouldn’t be ad-supported. Not only that he’s looking for other people that believes this thesis.

“The only way to get fulfillment is to help other people that believe what you believe.” – Simon Sinek

And I should add, Simon is very specific about what he means by “believe”:

“We want to go to work with people who understand us, who believe what we believe, who have a similar view of the world, that has nothing to do with their opinions and the differences that we share. That’s good. that’s called diversity. That’s called advantages to problem solving, which is we can all look at the same thing from different angle and come up with solutions. What I’m talking about is why should you help each other in the first place. What are you in the pursuit of?” – Simon Sinek [emphasis mine]

Dalton is in the pursuit of this crazy (gasp!) idea about a non-ad supported social media platform, and blogged about it repeatedly [a] [b] [c] [d]. He’s trying to find people who believes what he believes. He is proposing something that goes against the current tide and grain, because he believes it’s the way forward. He believes it’s something sustainable, a public good, and the springboard for further innovation. And when you find yourself in that situation, you need to find other people that believes what you believe to help you realize the vision of the future that betters us all.