Welcome to Symantec Connect.  Log in or register to participate.
Login to participate
Endpoint Management & Virtualization BlogsRSS

Running Python / Perl Scripts from Deployment Console or Task Management

zchandran's picture

Windows doesn't have a shebang/hashbang line like *nix does. This generally constrains the types of scripts that can be run from DS console or Task Management. Much as all of us Python users would like to do something like...

#!C:\python26\python.exe
import time
print "Hello world"
time.sleep(10)

... it just doesn't work because Windows isn't smart enough to pass it on to Python.

A workaround that I have kludged together is to paste the following lines into the top of the script:

rem -- This header cuts itself off -----
set fn=%temp%\%random%.py
copy %0 %fn%
echo 1,7de | edlin %fn%
C:\python26\python -u %fn%
exit
rem --- Do not edit above this line --

So that the finished product looks like this:

The script is comprised of DOS batch file commands so it should work on any Windows box. It does the following:

  1. Makes a copy of itself to a temporary file.
  2. Uses the built-in edlin to chop the top 7 lines from that temporary file.
  3. Runs the temporary file in Python.

This works without any additional components needing to be installed on the target box - besides the Python interpreter of course.

Perl (or your language of choice) should work similarly.