Execute a perl script from a vbscript
April 23rd, 2009 in Windows, vbscript. Add commentThis tip describes how to execute a perl script from windows vbscript. Although perl is used in this example, any command or program that runs on the DOS command prompt should be able to run from the vbscript this way.
Say you have a perl script called myperl.pl that takes an argument ‘-i’ in C:\Program Files\My Programs\perl and need to run it from a windows vbscript for whatever reason (An example may be a software installation routine that uses vbscript). The following vbscript snippet should help you achieve that.
Note that this example assumes that you have all the required perl libraries in the path and the perl script runs without errors when run manually from the DOS command line.
Set oShell = CreateObject("WScript.Shell")
sProgDir = "C:\Program Files\My Programs\perl\"
sArgs = "-i"
sExec = """" & sProgDir & "myperl.pl" & """"
sCmd = sExec & " " & sArgs
oShell.Run(sCmd)
Caveat: Look closely at the use of quotes. Looks weird, huh? But remember if you do not put these correctly you will get the obscure “80070002 cannot find the file error”.
Tags: windows vbscript shell


