我在我的nodejs代码中使用预构建的PhantomJS作为子进程,并且每次光栅化时都需要为浏览器设置一个TZ。
它作为子进程执行,如下:
childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
// handle results
});
调用函数时无法指定 TZ。
知道如何实现这一目标吗?
最佳答案
我们开始吧!使用options argument of the execFile function并将自定义 TZ=Europe/London
添加到子进程的环境中。
index.js
const execFile = require('child_process').execFile
const env = Object.assign(process.env, { 'TZ': 'Europe/London' })
const child = execFile('./env-test.js', { env }, (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log(stdout);
});
env-test.js(应该是可执行的chmod +x env-test.js
)
#!/usr/bin/env node
console.log(new Date().toString())
关于javascript - 在 PhantomJS 预构建中设置浏览器时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42778907/