1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php // Define el código Python como una cadena $pythonCode = ' import sys print("Hola Mundo desde Python") '; // Crea un archivo temporal para el script Python $tempFile = tempnam(sys_get_temp_dir(), 'py_'); file_put_contents($tempFile, $pythonCode); // Ejecuta el script Python usando el comando 'python3' $output = shell_exec("python3 " . escapeshellarg($tempFile)); // Muestra la salida del script Python echo "Salida desde Python: " . $output; // Limpia el archivo temporal unlink($tempFile); ?> |