Python script in Node.js

Application

适用于Node.js实现的小程序,在Node.js中创建一个进程供Python使用

Code added to Node.js

var exec = require('child_process').exec;
var arg1 = para1;
var arg2 = para2;
var filename = 'pyscript.py'
exec('python'+' '+filename+' '+arg1+' '+arg2,function(err,stdout,stderr){                
    if(stdout){console.log("py success", stdout);} 
    if(err){console.log("py fail", err);}
})

Code of Python

import sys 
python_script_name = sys.argv[0]
para1 = sys.argv[1]
print (para1)

供参考:Node.js中调用其他脚本
http://www.cnblogs.com/zhouji…

    原文作者:Lycheeee
    原文地址: https://segmentfault.com/a/1190000013294556
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞