mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
27 lines
669 B
JavaScript
27 lines
669 B
JavaScript
import { spawn } from 'child_process';
|
|
import path from 'path';
|
|
|
|
export function runPythonScript(scriptPath, args = []) {
|
|
return new Promise((resolve, reject) => {
|
|
const pythonProcess = spawn('python', [scriptPath, ...args]);
|
|
|
|
let stdout = '';
|
|
let stderr = '';
|
|
|
|
pythonProcess.stdout.on('data', (data) => {
|
|
stdout += data.toString();
|
|
});
|
|
|
|
pythonProcess.stderr.on('data', (data) => {
|
|
stderr += data.toString();
|
|
});
|
|
|
|
pythonProcess.on('close', (code) => {
|
|
if (code === 0) {
|
|
resolve(stdout);
|
|
} else {
|
|
reject(new Error(`Python script exited with code ${code}: ${stderr}`));
|
|
}
|
|
});
|
|
});
|
|
} |