gpt4 book ai didi

node.js - 如何使用 nodejs child_process exec 访问 cucumber.js 步骤定义中的标准输出、标准错误和错误

转载 作者:搜寻专家 更新时间:2023-11-01 00:02:55 24 4
gpt4 key购买 nike

我是 Cucumber.js 的新手,试图在步骤定义中执行 shell 命令。下面的示例是一个步骤定义片段,Cucumber.js 不打印标准输出。我基本上需要一步访问 stdout 和 stderr。

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();
});

最佳答案

看起来像是 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);
});

关于node.js - 如何使用 nodejs child_process exec 访问 cucumber.js 步骤定义中的标准输出、标准错误和错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14466659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com