用的nohup不工作phantomjs [英] phantomjs with nohup not working

查看:331
本文介绍了用的nohup不工作phantomjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是想用nohup命令通过ssh运行 phantomjs 脚本。但扔的nohup我在中的nohup.out 文件的错误。

我的命令是 - >

 的nohup phantomjs example.js&安培;

phantomjs example.js 无nohup的完美运行。我还创建了一个bash脚本来运行的nohup但两者时间这个命令,我得到这个错误 - >

  events.js:72
        扔儿; //未处理的'错误'事件
              ^
错误:EBADF,阅读

** example.js的code

  VAR页=要求('网页')。创建()
    系统=要求(系统),
    地址,输出大小;如果(system.args.length 3; || system.args.length→5){
    的console.log('用法:rasterize.js URL文件名[paperwidth * paperheight | paperformat] [变焦]');
    的console.log('纸(PDF格式输出)的例子:5英寸* 7.5in,10厘米*20厘米,A4,书);
    的console.log('图像(PNG / JPG输出)的例子:1920px整个页面,窗口宽度1920px');
    的console.log('* 800像素600px的窗口中,裁剪为800x600');
    phantom.exit(1);
}其他{
    地址= system.args [1];
    输出= system.args [2];
    page.viewportSize = {宽度:600,高度:600};
    如果(system.args.length→3&放大器;&放大器; system.args [2] .substr(-4)===.PDF){
        大小= system.args [3] .split('*');
        page.paperSize = size.l​​ength === 2? {宽度尺寸[0],身高:尺寸[1],保证金:'0像素'}
                                           :{格式:system.args [3],方向:纵向,保证金:'1厘米'};
    }否则如果(system.args.length→3&放大器;&放大器; system.args [3] .substr(-2)===像素){
        大小= system.args [3] .split('*');
        如果(size.l​​ength === 2){
            页宽= parseInt函数(大小[0],10);
            pageHeight = parseInt函数(尺寸[1],10);
            page.viewportSize = {宽度:页宽,高度:pageHeight};
            page.cli preCT = {顶:0,左:0,宽度:页宽,高度:pageHeight};
        }其他{
            的console.log(大小,system.args [3]);
            页宽= parseInt函数(system.args [3],10);
            pageHeight = parseInt函数(页宽* 3/4​​,10); //这是好一个假设的任何
            的console.log(pageHeight:,pageHeight);
            page.viewportSize = {宽度:页宽,高度:pageHeight};
        }
    }
    如果(system.args.length→4){
        page.zoomFactor = system.args [4];
    }
    page.open(地址,功能(状态){
        如果(状态!=='成功'){
            的console.log('无法加载地址!');
            phantom.exit();
        }其他{
            window.setTimeout(函数(){
                page.render(输出);
                phantom.exit();
            },200);
        }
    });
}


解决方案

有同样的问题与1.9.8和1.1.0 casperjs-β3。
我需要作出后台进程反过来所以不是nohup的-ING我做了启动和分离过程:

 <按Ctrl + Z>
BG
不认1%

I was trying to run phantomjs script via ssh using nohup command . But nohup threw an error which i found in nohup.out file.

My command was -->

nohup phantomjs example.js &

phantomjs example.js run perfectly without nohup . I have also created a bash script to run this command with nohup but both time, I got this error -->

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: EBADF, read

** code of example.js

var page = require('webpage').create(),
    system = require('system'),
    address, output, size;

if (system.args.length < 3 || system.args.length > 5) {
    console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
    console.log('  paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
    console.log('  image (png/jpg output) examples: "1920px" entire page, window width 1920px');
    console.log('                                   "800px*600px" window, clipped to 800x600');
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    page.viewportSize = { width: 600, height: 600 };
    if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
        size = system.args[3].split('*');
        page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
                                           : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
    } else if (system.args.length > 3 && system.args[3].substr(-2) === "px") {
        size = system.args[3].split('*');
        if (size.length === 2) {
            pageWidth = parseInt(size[0], 10);
            pageHeight = parseInt(size[1], 10);
            page.viewportSize = { width: pageWidth, height: pageHeight };
            page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight };
        } else {
            console.log("size:", system.args[3]);
            pageWidth = parseInt(system.args[3], 10);
            pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any
            console.log ("pageHeight:",pageHeight);
            page.viewportSize = { width: pageWidth, height: pageHeight };
        }
    }
    if (system.args.length > 4) {
        page.zoomFactor = system.args[4];
    }
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
            phantom.exit();
        } else {
            window.setTimeout(function () {
                page.render(output);
                phantom.exit();
            }, 200);
        }
    });
}

解决方案

Had the same problem with 1.9.8 and casperjs 1.1.0-beta3. I needed to make the process turn in background so instead of nohup-ing what I did is launched and detached the process :

<Ctrl+Z>
bg
disown %1

这篇关于用的nohup不工作phantomjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆