spawn.js 678 B

123456789101112131415161718192021222324252627282930313233
  1. var
  2. fs = require('fs'),
  3. tmp = require('../lib/tmp');
  4. function _writeSync(stream, str, cb) {
  5. var flushed = stream.write(str);
  6. if (flushed) {
  7. return cb(null);
  8. }
  9. stream.once('drain', function _flushed() {
  10. cb(null);
  11. });
  12. }
  13. module.exports.out = function (str, cb) {
  14. _writeSync(process.stdout, str, cb);
  15. };
  16. module.exports.err = function (str, cb) {
  17. _writeSync(process.stderr, str, cb);
  18. };
  19. module.exports.exit = function () {
  20. process.exit(0);
  21. };
  22. var type = process.argv[2];
  23. module.exports.tmpFunction = (type == 'file') ? tmp.file : tmp.dir;
  24. var arg = (process.argv[3] && parseInt(process.argv[3], 10) === 1) ? true : false;
  25. module.exports.arg = arg;