(NodeJs) PhantomJs 子进程的命令行参数以及脚本参数
(NodeJs) Command line arguments to PhantomJs child process along with script args
我有以下有效的代码:
var Path = require('path')
var Phantomjs = require('phantomjs2')
var phantomjsPath = Phantomjs.path
var childArgs = [
Path.join(__dirname, 'phantomjs-worker.js'),
'http://...some login url...',
3000, //login timeout
'http://...some address to render as image...',
5000, //address timeout
'...output image file path...',
1000, //page width
1000, //page height
1234 //some id
]
var child = Proc.spawn(phantomjsPath, childArgs, { cwd: process.cwd() })
里面幻影-worker.js:
var argsOffset = 0;
var login = system.args[argsOffset + 1];
var logintimeout = system.args[argsOffset + 2];
var address = system.args[argsOffset + 3];
var addresstimeout = system.args[argsOffset + 4];
var output = system.args[argsOffset + 5];
var pageWidth = parseInt(system.args[argsOffset + 6]);
var pageHeight = parseInt(system.args[argsOffset + 7]);
var pageId = system.args[argsOffset + 8];
...
我需要能够通过
--ignore-ssl-errors=true --ssl-protocol=tlsv1
还有。
我尝试将它们添加为前 2 个参数,但它不起作用。它出于某种原因开始寻找输出图像文件路径,但显然失败了。
有没有办法将这些命令行参数与脚本及其子参数一起传递?
以下按预期工作。错误不在这部分代码中。相反,幻影进程由于内存问题而退出,导致无法创建渲染图像文件。
var Path = require('path')
var Phantomjs = require('phantomjs2')
var phantomjsPath = Phantomjs.path
var childArgs = [
'--ignore-ssl-errors=true',
'--ssl-protocol=any',
'--web-security=false',
Path.join(__dirname, 'phantomjs-worker.js'),
'http://...some login url...',
3000, //login timeout
'http://...some address to render as image...',
5000, //address timeout
'...output image file path...',
1000, //page width
1000, //page height
1234 //some id
]
var child = Proc.spawn(phantomjsPath, childArgs, { cwd: process.cwd() })
工人:
var webpage = require('webpage'),
system = require('system');
var login = system.args[1];
var logintimeout = system.args[2];
var address = system.args[3];
var addresstimeout = system.args[4];
var output = system.args[5];
var pageWidth = parseInt(system.args[6]);
var pageHeight = parseInt(system.args[7]);
var pageId = system.args[8];
我有以下有效的代码:
var Path = require('path')
var Phantomjs = require('phantomjs2')
var phantomjsPath = Phantomjs.path
var childArgs = [
Path.join(__dirname, 'phantomjs-worker.js'),
'http://...some login url...',
3000, //login timeout
'http://...some address to render as image...',
5000, //address timeout
'...output image file path...',
1000, //page width
1000, //page height
1234 //some id
]
var child = Proc.spawn(phantomjsPath, childArgs, { cwd: process.cwd() })
里面幻影-worker.js:
var argsOffset = 0;
var login = system.args[argsOffset + 1];
var logintimeout = system.args[argsOffset + 2];
var address = system.args[argsOffset + 3];
var addresstimeout = system.args[argsOffset + 4];
var output = system.args[argsOffset + 5];
var pageWidth = parseInt(system.args[argsOffset + 6]);
var pageHeight = parseInt(system.args[argsOffset + 7]);
var pageId = system.args[argsOffset + 8];
...
我需要能够通过
--ignore-ssl-errors=true --ssl-protocol=tlsv1
还有。
我尝试将它们添加为前 2 个参数,但它不起作用。它出于某种原因开始寻找输出图像文件路径,但显然失败了。
有没有办法将这些命令行参数与脚本及其子参数一起传递?
以下按预期工作。错误不在这部分代码中。相反,幻影进程由于内存问题而退出,导致无法创建渲染图像文件。
var Path = require('path')
var Phantomjs = require('phantomjs2')
var phantomjsPath = Phantomjs.path
var childArgs = [
'--ignore-ssl-errors=true',
'--ssl-protocol=any',
'--web-security=false',
Path.join(__dirname, 'phantomjs-worker.js'),
'http://...some login url...',
3000, //login timeout
'http://...some address to render as image...',
5000, //address timeout
'...output image file path...',
1000, //page width
1000, //page height
1234 //some id
]
var child = Proc.spawn(phantomjsPath, childArgs, { cwd: process.cwd() })
工人:
var webpage = require('webpage'),
system = require('system');
var login = system.args[1];
var logintimeout = system.args[2];
var address = system.args[3];
var addresstimeout = system.args[4];
var output = system.args[5];
var pageWidth = parseInt(system.args[6]);
var pageHeight = parseInt(system.args[7]);
var pageId = system.args[8];