nodejs 执行python脚本

来源:互联网 发布:js两个对象数组合并 编辑:程序博客网 时间:2024/05/16 06:16

nodejs提供了child_process用于调用外部程序 

child_process.exec(command[, options][, callback])

代码如下

Python代码见另一篇文章

const cp=require('child_process')
var arg1='美元',
arg2='日元'
cp.exec('python test_py.py '+arg1+' '+arg2+' ', (err, stdout,stderr) => {
if (err)console.log('stderr',err);
if (stdout)console.log('stdout',stdout);
})

输出结果

stdout ('\xe7\xbe\x8e\xe5\x85\x83', '\xe6\x97\xa5\xe5\x85\x83')
helloNodeJS.js:27
(['\xe7\xbe\x8e\xe5\x85\x83', '659.41', '653.99', '662.05', '662.05', '660.34', '2017-11-30'], ['\xe6\x97\xa5\xe5\x85\x83', '5.8788', '5.6957', '5.9201', '5.9201', '5.8945', '2017-11-30'])

原创粉丝点击