我在python中有自定义语言的词法分析器和解析器,但由于某种原因我也需要使用JS。首先,我认为我会再次在JS中构建两个函数(词法分析器和解析器),但只能在Python中使用。
有什么方法可以在我的JS代码中调用两个Python函数。我在Stack Overflow上看到了其他问题,但我希望能够向函数发送参数并从这些函数中获取数据。
请建议我可以使用的任何技巧或方法。
答案 0 :(得分:0)
Node.js has a package called child_process and it has an exec
function to execute any local script or program that you have. Here is a sort of boilerplate example:
const exec = require('child_process').exec;
var yourscript = exec('sh ~/some_bash.sh', (error, stdout, stderr) => {
console.log('${stdout}');
console.log('${stderr}');
if (error !== null) {
console.log('Uh oh! Error: ${error}');
}
});