Created
July 18, 2011 17:23
-
-
Save jstorimer/1090096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
# A useful little script to execute a shell command when another | |
# command exits successfully. Kind of like using && except the | |
# first command will keep executing until it returns successfully. | |
# | |
# My use case was starting up a local rails server. It takes ~15 | |
# seconds and I have no indication of when it's ready besides manually | |
# polling lsof. So with this script I just do the following to start | |
# profiling my app when it's online. | |
# | |
# $ when lsof -i :3000 && ab -c10 -n100 http://127.0.0.1:3000/ | |
spawn = require('child_process').spawn | |
sys = require 'sys' | |
prog = process.argv.slice(2, 3)[0] | |
args = process.argv.slice 3, process.argv.length | |
testProgram = (prog, args) -> | |
test = spawn prog, args | |
test.on 'exit', (code) -> | |
if code == 0 | |
sys.print "\n" | |
process.exit 0 | |
else | |
sys.print '.' | |
callback = -> testProgram prog, args | |
setTimeout callback, 1000 | |
testProgram prog, args | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment