最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - check if child_process has ended in node.js? - Stack Overflow

programmeradmin0浏览0评论

I am creating a cakefile using node.js and want to know if a child_process has ended before moving on the next one.

{exec} = require 'child_process'
 exec 'casperjs test.js', (err, stdout, stderr) ->
        err && throw err
        log stdout
        if //exec has finished
          log "finished executing"

I am creating a cakefile using node.js and want to know if a child_process has ended before moving on the next one.

{exec} = require 'child_process'
 exec 'casperjs test.js', (err, stdout, stderr) ->
        err && throw err
        log stdout
        if //exec has finished
          log "finished executing"
Share Improve this question edited Nov 11, 2012 at 14:31 maba 48.1k10 gold badges110 silver badges118 bronze badges asked Nov 11, 2012 at 14:30 unknownunknown 8663 gold badges16 silver badges38 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

When the callback of exec is called, the process has already been terminated. There's no need to add an additional check.

For spawn, you can bind an exit event listener.

Alternativly you can use 'execSync", in order to go on step by step

var c = require('child_process');
var cliCommand = 'ls';
var result = c.execSync(cliCommand);
发布评论

评论列表(0)

  1. 暂无评论