Deployment Solution

 View Only

Running Python / Perl Scripts from Deployment Console or Task Management 

Nov 17, 2008 11:42 AM

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.

Statistics
0 Favorited
1 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
jpg file
6284.jpg   2 KB   1 version
Uploaded - Apr 10, 2020

Tags and Keywords

Comments

Dec 15, 2011 02:27 AM

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

Related Entries and Links

No Related Resource entered.