Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何促使nodejs child_process exec使用es6_Node.js_Exec_Child Process_Es6 Promise - Fatal编程技术网

Node.js 如何促使nodejs child_process exec使用es6

Node.js 如何促使nodejs child_process exec使用es6,node.js,exec,child-process,es6-promise,Node.js,Exec,Child Process,Es6 Promise,我有一个phantomjs脚本,它将url作为命令行参数,并在stdout中返回主体html内容 当我通过phantomjs脚本通过promise调用接收html内容时,我通过cheerio调用parsePage()来操作数据,然后通过gatherenext() 但我不能保证执行功能?我怎样才能做到这一点 编辑: 我找到了这个lib:github.com/sindresorhus/execa,它解决了承诺问题,但我遇到了另一个问题。也就是说,对于下一个页面(即页面分页2、3、4、5等),子fun

我有一个phantomjs脚本,它将url作为命令行参数,并在stdout中返回主体html内容

当我通过phantomjs脚本通过promise调用接收html内容时,我通过
cheerio
调用parsePage()来操作数据,然后通过gatherenext()

但我不能保证执行功能?我怎样才能做到这一点

编辑:

我找到了这个lib:github.com/sindresorhus/execa,它解决了承诺问题,但我遇到了另一个问题。也就是说,对于下一个页面(即页面分页2、3、4、5等),子func承诺将始终返回下一个页面的旧页面(第一页的html内容)。。为什么会发生这种情况?有什么想法吗

以下是对此的修改代码:

let child = (pager) => {
        let command = cmdBase + pager;
        console.log('command: ', command);
        return execa.shell(command).then(result => {
            return result.stdout;
        });
    };
或者,还有更好的解决方案吗


谢谢

我不知道这是否相关,但您有一些无关的右括号(
})应该是
}
;)谢谢,但还是不行!我得到了这个lib,它解决了承诺问题,但我得到了另一个问题。也就是说,对于每一个下一页(即分页2、3、4、5等),
child
func promise始终返回下一页的旧内容(第一页的html内容)。。为什么在这种情况下会出现这种现象?知道吗?我不知道这是否相关,但你有一些无关的右括号(
})应该是
}
;)谢谢,但还是不行!我得到了这个lib,它解决了承诺问题,但我得到了另一个问题。也就是说,对于每一个下一页(即分页2、3、4、5等),
child
func promise始终返回下一页的旧内容(第一页的html内容)。。为什么在这种情况下会出现这种现象?有什么想法吗?
let child = (pager) => {
        let command = cmdBase + pager;
        console.log('command: ', command);
        return execa.shell(command).then(result => {
            return result.stdout;
        });
    };