2017-06-02 312 views
0

实际上,我可以运行这个python脚本,并且此脚本在终端中运行时创建csv文件。但是,当我在nodejs后端运行这个文件不能创建一个csv文件。我在哪里犯错误?Nodejs使用PythonShell运行python脚本

这里是pythonshell主页:https://github.com/extrabacon/python-shell

var options = { 
    mode: 'text', 
    scriptPath: './views', 
    args: [informations["camera_id"], informations.start_s, informations.start_min, informations.start_h, informations.start_d, informations.start_mon, informations.start_y, informations.end_s, informations.end_min, informations.end_h, informations.end_d, informations.end_mon, informations.end_y] 
    }; 

var pyshell = new PythonShell('historical_inquiry_1.py', options); 
    pyshell.on('message', function (message) { 
    console.log("script message : ",message); 
    }); 

这里是Python脚本(测试是一个数组):

... 
with open("test.csv", "w") as text_file: 
     text_file.write(test) 
... 

事实上,我会用这个巨大的查询结果。正常的方式结果是超时。你可以给我的错,我们更好的方式来采取巨大的MongoDB查询结果。 在此先感谢。

回答

0

检查您的nodejs工作目录是否包含您的Python脚本views/historical_inquiry_1.py的目录。我建议你在scriptPathoptions中使用绝对路径。