我在尝试执行脚本并获取其输出时遇到了NodeJS错误。
我收到以下错误:
TypeError: invalid data
at WriteStream.Socket.write (net.js:623:11)
at Object.execFileSync (child_process.js:482:20)
at doRender (/test/apps/application/routes/TEST.js:1786:26)
我猜这是因为误用了NodeJS原生execFileSync
函数,但到目前为止,我已经尝试了很多东西来匹配documentation而没有任何成功。
这是我的代码:
router.get("/stat", authReader, function (req, res) {
//Current file is in application/routes
var doRender = function (req, res) {
var output;
//I want to execute application/scripts/test.bash
output= child_process.execFileSync("test.bash",[], {
cwd: "../scripts"
});
result= processDataFromCSV(output);
//processing data in response
res.render(acronym + "_test", {
title: "CSV output",
result: result,
});
}
doRender(req, res);
}
你可以帮我理解我做错了什么吗?非常感谢任何帮助。
答案 0 :(得分:0)
验证您的test.bash
是否可执行,或使用/bin/bash test.bash
像child_process.execSync()
一样运行它。有关详细信息,请查看此answer by Sravan here;