fix python stdout and stderr integration

This commit is contained in:
wea_ondara
2024-05-29 18:37:31 +02:00
parent c8edb1da45
commit d6ef6ea1dc
2 changed files with 4 additions and 5 deletions

View File

@@ -76,10 +76,11 @@ export default class AiPythonConnector {
const port = await this.port();
return await new Promise((resolve, reject) => {
console.log('ai: starting python backend');
this.process = exec('. ../.venv/bin/activate && cd ../ai && python3 main.py --port ' + port);
this.process = exec('. ../.venv/bin/activate && cd ../ai && python3 main.py --port ' + port,
{env: {'PYTHONUNBUFFERED': '1'}});
this.process.stdout!.on('data', (data) => {
console.log('ai: ' + data.toString());
console.log('ai: ' + data.toString().replace(/\r?\n$/, ''));
if (data.includes('' + port)) {
console.log('ai: python backend started');
resolve();
@@ -87,7 +88,7 @@ export default class AiPythonConnector {
});
this.process.stderr!.on('data', (data) => {
console.error('ai: ' + data.toString());
console.error('ai: ' + data.toString().replace(/\r?\n$/, ''));
});
this.process.on('exit', (code) => {