Video Screencast Help
Search Video Help Close Back
to help
New in the Rewards Catalog: Vouchers for "Symantec Technical Specialist" and "Symantec Certified Specialist" exams.

Running Python / Perl Scripts from Deployment Console or Task Management

Updated: 17 Nov 2008 | 1 comment
zchandran's picture
0 0 Votes
Login to vote

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.

Comments

mhteam's picture
14
Dec
2011
0 Votes 0
Login to vote

how can i do this with Perl? didn't work for me.

i understand the tip but it doesn't work for me with perl