I spawn a python child process in javascript (for coding a Bot with Microsoft Botframework) like this:
(我在JavaScript中产生了一个python子进程(用于使用Microsoft Botframework编码Bot),如下所示:)
async function searchForRelevantDoc (context) {
var msg = context.activity.text;
var spawn = require('child_process').spawn,
py = spawn('python', ['../path/to/file.py', msg]),
output = '';
py.stdin.setEncoding = 'utf-8';
py.stdout.on('data',
(data) => {
output += data.toString();
console.log('output was generated: ' + output);
});
// Handle error output
py.stderr.on('data', (data) => {
// As said before, convert the Uint8Array to a readable string.
console.log('error:' + data);
});
py.stdout.on('end', async function(code){
console.log('output: ' + output);
console.log(`Exit code is: ${code}`);
// "return" is probably wrong, what should be done instead?
return output;
}
});
}
I want output
to be returned as the value of the function searchForRelevanceDoc()
.
(我希望将output
作为函数searchForRelevanceDoc()
的值searchForRelevanceDoc()
。)
How can this be done?(如何才能做到这一点?)
I am not able to use await context.sendActivity(output)
instead of the return statement.(我不能使用await context.sendActivity(output)
而不是return语句。)
Error message:(错误信息:)
TypeError: Cannot perform 'get' on a proxy that has been revoked
Function searchForRelevanceDoc
is called like so:
(函数searchForRelevanceDoc
的调用方式如下:)
//in bot.js
const pysearch = require('../bboti/python-search');
class MyBot {
// constructor...
async onTurn(context) {
// ...
var search_engine_answer = pysearch.searchForRelevantDoc(context);
context.sendActivity(search_engine_answer)
// ...
}
}
ask by Lady_Hangaku translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…