Created
November 1, 2012 01:09
Revisions
-
dansteingart created this gist
Nov 1, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ //First make placeholders for results as globals results = {} processes = {} //Now Spawn Processes within code you need, where index is an identifier spawn_list[index] = spawn(/*file here*/) processes[index] = spawn_list[index].pid results[processes[index]] = {} results[processes[index]]['index'] = index //funny looking but important results[processes[index]]['stdout'] = "" results[processes[index]]['stderr'] = "" spawn_list[index].stdout.on('data',function(data){results[processes[index]]['stdout'] += data}) spawn_list[index].stderr.on('data',function(data){results[processes[index]]['stderr'] += data}) spawn_list[page_name].on('exit',function(code) { this_pid = this.pid console.log(this_pid) console.log(code) stdout = results[this_pid]['stdout'] stderr = results[this_pid]['stderr'] this_index = results[this_pid]['index'] end_time = new Date().getTime() big_out = {'out':stdout,'outerr':stderr} //do something with bigoutput //...... //Clean up, clean up, everybody clean up delete processes[this_index]; delete spawn_list[this_index]; delete results[this_index]; })