how to access stdout,stderr, and error in cucumber

2019-07-03 00:26发布

I am new to Cucumber.js, trying to execute a shell command in a step definition. Sample below is a step definition snippet, Cucumber.js does not print stdout. I basically need to access stdout and stderr in a step.

var exec = require('child_process').exec;

this.Given(/^XYZ server is running$/, function(callback) {
child = exec('pwd', function (error, stdout, stderr) {
  console.log('stdout: ' + stdout);
  console.log('stderr: ' + stderr);
  if (error !== null) {
    console.log('exec error: ' + error);
  }
});
callback();
});

1条回答
疯言疯语
2楼-- · 2019-07-03 00:39

Looks like a good example on nodejitsu.

 var childProcess = require('child_process'),
     ls;

 ls = childProcess.exec('ls -l', function (error, stdout, stderr) {
   if (error) {
     console.log(error.stack);
     console.log('Error code: '+error.code);
     console.log('Signal received: '+error.signal);
   }
   console.log('Child Process STDOUT: '+stdout);
   console.log('Child Process STDERR: '+stderr);
 });

 ls.on('exit', function (code) {
   console.log('Child process exited with exit code '+code);
 });
查看更多
登录 后发表回答