| 1 |
'use strict'; |
| 2 |
var cp = require('child_process'); |
| 3 |
|
| 4 |
process.env = {}; |
| 5 |
|
| 6 |
var index = +process.argv[2] || 0 |
| 7 |
if (index <= 1) { |
| 8 |
console.log(0) |
| 9 |
return |
| 10 |
} |
| 11 |
if (index == 2) { |
| 12 |
console.log(1) |
| 13 |
return |
| 14 |
} |
| 15 |
|
| 16 |
function getFromChild(n, cb) { |
| 17 |
var proc = cp.spawn(process.execPath, [__filename, n]) |
| 18 |
var stdout = '' |
| 19 |
proc.stdout.on('data', function (data) { stdout += data }) |
| 20 |
proc.on('close', function () { |
| 21 |
cb(null, +stdout) |
| 22 |
}) |
| 23 |
proc.on('error', cb) |
| 24 |
} |
| 25 |
|
| 26 |
getFromChild(index - 1, function(err, result1) { |
| 27 |
if (err) throw err |
| 28 |
getFromChild(index - 2, function(err, result2) { |
| 29 |
if (err) throw err |
| 30 |
console.log(result1 + result2) |
| 31 |
}) |
| 32 |
}) |