<?php
// Runs the Python script, waits for completion, and returns its output.

$cmd = 'python3 /var/www/html/modules/EcmInvoiceOuts/ai/test.py';
$output = [];
$returnVar = 0;
exec($cmd . ' 2>&1', $output, $returnVar);

if ($returnVar !== 0) {
    http_response_code(500);
    echo "Error running Python script:\n" . implode("\n", $output);
    exit;
}

// Expect a single line with the count
echo trim(implode("\n", $output));
