我试图通过 child_process.spawn 系统使用我的 javascript 文件运行 python 脚本,但它似乎永远不会在 aws lambda 上运行。
相关代码是:
getEntities: function (){
var spawn = require('child_process').spawn;
var py = spawn('python', ['mainPythonFile.py']);
var outputString = "starting string";
console.log("BEFORE ANY INPUT");
py.stdout.on('data', function (data) {
console.log("----Getting information from the python script!---");
outputString += data.toString();
console.log(outputString);
});
py.stdout.on('end', function (){
console.log("===hello from the end call in python files===");
console.log("My output : " + outputString);
});
console.log("NO INPUT CHANGED??");
return outputString;
}
这些文件位于文件夹结构的同一级别(表面级别)。
正在运行的 python 文件非常简单,只包含一些打印语句:
主要Python文件:
import sys;
print("Hello There");
print("My name is Waffles");
print("Potato Waffles");
sys.stdout.flush()
The output我从 aws 服务得到的是这样的:
BEFORE ANY INPUT
NO INPUT CHANGED??
starting string
我尝试了不同的路径来尝试访问 python 文件,例如*mainPythonFile.py
./mainPythonFile.py
etc.
我觉得代码似乎没问题,因为这适用于我的本地计算机,但是尝试让它在 AWS 上运行有一个我无法理解的微妙之处。
如果需要,我可以提供任何其他信息。
注意:“getEntities”函数正在被另一个node.js 文件调用,但我将代码移至调用函数,得到了相同的结果。