forked from TJkrusinski/NodePDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchild.js
More file actions
40 lines (34 loc) · 852 Bytes
/
child.js
File metadata and controls
40 lines (34 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
var child = require('child_process');
var shq = require('shell-quote').quote;
var which = process.platform == 'win32' ? 'where' : 'which';
/**
* Execute the command
*
* @param {String} url
* @param {String} filename
* @param {Object} options
* @param {Function} [cb]
*/
exports.exec = function(url, filename, options, cb){
var key;
var stdin = ['phantomjs'];
stdin.push(options.args);
stdin.push(shq([
__dirname+'/render.js',
url,
filename,
JSON.stringify(options),
]));
return child.exec(stdin.join(' '), function(err, stdo, stde){
cb ? cb(err) : null;
});
};
/**
* Check to see if the environment has a command
*/
exports.supports = function(cb, cmd) {
var stream = child.exec(which+' '+(cmd || 'phantomjs'), function(err, stdo, stde){
return cb(!!stdo.toString());
});
};