{"cells":[{"cell_type":"code","source":["import os\n","    import datetime\n","    import sys\n","\n","    # Ruta para un nuevo archivo de log de prueba\n","    log_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), \"logs\", \"test_iis_exec.log\")\n","\n","    try:\n","        # Intenta escribir en el archivo de log\n","        with open(log_file_path, \"a\", encoding=\"utf-8\") as f:\n","            timestamp = datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S.%f\")\n","            f.write(f\"[{timestamp}] test_iis_exec.py FUE EJECUTADO.\\n\")\n","            f.write(f\"[{timestamp}] Python Executable: {sys.executable}\\n\")\n","            f.write(f\"[{timestamp}] Python Version: {sys.version}\\n\")\n","            f.write(f\"[{timestamp}] Current Working Directory: {os.getcwd()}\\n\")\n","\n","        # Salida HTTP mínima requerida por HttpPlatformHandler para no dar error 502.3\n","        print(\"Content-type: text/html\\n\\n\")\n","        print(\"<html><body><h1>Script de prueba ejecutado. Revisa test_iis_exec.log.</h1></body></html>\")\n","\n","    except Exception as e:\n","        # Si hay un error al escribir en el log, intenta imprimirlo a stdout\n","        # (que debería ir a httpplatform_stdout.log)\n","        error_timestamp = datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S.%f\")\n","        print(\"Content-type: text/html\\n\\n\", file=sys.stderr) # Enviar a stderr\n","        print(f\"<html><body><h1>ERROR EN test_iis_exec.py</h1><p>Error al intentar escribir en el log: {e}</p><p>Timestamp: {error_timestamp}</p></body></html>\", file=sys.stderr)\n","\n","        # También intenta escribir el error en el log de prueba si es posible\n","        try:\n","            with open(log_file_path, \"a\", encoding=\"utf-8\") as f:\n","                f.write(f\"[{error_timestamp}] ERROR en test_iis_exec.py: {e}\\n\")\n","        except:\n","            pass # No hacer nada si esto también falla\n","\n","    # Pequeña pausa para asegurar que HttpPlatformHandler tenga tiempo de procesar la salida\n","    import time\n","    time.sleep(0.1)\n","    sys.exit(0) # Salir explícitamente"],"outputs":[{"output_type":"error","ename":"IndentationError","evalue":"unexpected indent (<ipython-input-1-3dc60cdc6bc9>, line 2)","traceback":["\u001b[0;36m  File \u001b[0;32m\"<ipython-input-1-3dc60cdc6bc9>\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m    import datetime\u001b[0m\n\u001b[0m    ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unexpected indent\n"]}],"execution_count":1,"metadata":{"id":"PDPWPSCRsaYz","executionInfo":{"status":"error","timestamp":1747811686306,"user_tz":-120,"elapsed":58,"user":{"displayName":"JOSE JAVIER MARTINEZ GALIPIENSO","userId":"08359553291676043373"}},"outputId":"6e696f96-ea57-4477-c535-9cef2fe56439","colab":{"base_uri":"https://localhost:8080/","height":106}}}],"metadata":{"colab":{"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"}},"nbformat":4,"nbformat_minor":0}