Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a Perl File (.pl) from ASP

Status
Not open for further replies.

jw2000

Programmer
Aug 12, 2005
105
US
How can I run a Perl file (.pl) from ASP?
 
I am currently using running a perl script (.pl) from the Command Prompt. How can I run this .pl file from ASP?
 
You could create a wscript.shell object and use it's Run or Exec function to execute it, provided the default web user has execute permissions on the perl executable. Example of a ping with shell object:
Code:
<%
Option Explicit

Dim WshShell, pngExec, strComputer
Set WshShell = Server.CreateObject("wscript.shell")
strComputer = "localhost"
'Ping Computer
set pngExec = WshShell.exec("ping -n 4 " & strComputer)

Response.Write "<pre>"
do until pngExec.StdOut.AtEndOfStream
	Response.Write pngExec.StdOut.Read(1)
	Response.Flush
loop
Response.Write "</pre>"
%>

Hope this answers your question,
-T

barcode_1.gif
 
Hello Tarwn,

The perl file is in C:/myPerlFiles/perl1.pl

How do I run perl1.pl from ASP? perl1.pl also prints out messages when it's running ... can I see these in ASP as well?


 
jw2000,

You can modify Tarwn's code for your purposes.

When doing this, one thing it will be helpful to know is that the Ping program is located in the PATH environment variable because it is in %SystemRoot%\system32

If it wasn't in the PATH and it also wasnt in the current working directory of the IUSR_MachineName account used by ASP then it would need to be executed with a command line such as: C:\WinNT\System32\ping.exe
 
The argument to WshShell.exec() is a command you want to execute (basically what you would type on the command-line). pngExec.stdOut is the StdOut pipe from whatever you executed. The easiest modification of my example script would be along the lines of:
Code:
<%
Option Explicit

Dim WshShell, pngExec
Set WshShell = Server.CreateObject("wscript.shell")


set pngExec = WshShell.exec("C:\Perl\perl.exe C:\myPerlFiles\perl1.pl")

Response.Write "<pre>"
do until pngExec.StdOut.AtEndOfStream
    Response.Write pngExec.StdOut.Read(1)
    Response.Flush
loop
Response.Write "</pre>"
%>

However there are other ways to capture the output, I had intentionally wanted to flush the output regularly in my script. If you search on wscript.shell and exec you should be able to find a ton of examples.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top