I have a script that is called by a batch file. Whether or not the script completes successfully the batch file continues. I need to know the results of the script. Is there a way to open an IE session, and call a CF page that I can pass an exit code to in the URL? Also, how would I generate an exit code to pass? Thanks

Dani AI

Generated

Short answer: have the Python script return an integer (use sys.exit(n)), capture that in the batch via %ERRORLEVEL%, and then launch IE with the code in the query string — or, even better, have Python call the ColdFusion URL directly. pointed toward using the Python Win32 extensions if you want to automate the browser via COM; that works, but for a simple status POST/GET it’s cleaner to send the HTTP request from Python instead of popping up IE.

Example batch flow (captures Python exit code and starts IE; note the empty title for start and a small timestamp token to avoid caching):

@echo off
python "C:\path\script.py"
set rc=%ERRORLEVEL%
start "" "C:\Program Files\Internet Explorer\iexplore.exe" "http://yourserver/result.cfm?code=%rc%&ts=%RANDOM%"
exit /b %rc%

How to generate the exit code in Python:

# script.py
import sys

# ... do work ...
# return 0 for success, non-zero for specific errors
sys.exit(2)

If you want to control IE from Python (COM) or simply notify the CF page without a browser, examples:

# pywin32: open IE and navigate (requires win32com)
from win32com.client import Dispatch
import time

ie = Dispatch("InternetExplorer.Application")
ie.Visible = True
ie.Navigate("http://yourserver/result.cfm?code=2")
while ie.ReadyState != 4:
    time.sleep(0.1)
# direct HTTP call (recommended if you don't need a UI)
import urllib.request
urllib.request.urlopen("http://yourserver/result.cfm?code=2")

Caveats: keep return codes simple (0 = success, small non-zero values for errors — staying <256 avoids surprises), remember services/scheduled tasks often can’t open an interactive browser, and avoid sending sensitive details in a GET querystring. If the goal is just status reporting, a server-side POST or a direct HTTP call from Python is more reliable than automating a browser.

For COM support with IE you need to download the Python Win32 Extensions from:

That installation package also includes a number of sample files you might be intersted in.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.