[thelist] Execute external command in ASP

Joe Ngo chilijoe at gmail.com
Thu Aug 18 10:23:03 CDT 2005

On 7/26/05, Canfield, Joel <JCanfield at pacadvantage.org> wrote:
> > is there a way to execute and external command-line program in classic
> > ASP and capture its output? I'm looking for something similar to the
> > system() command in PHP.
> I've used WSCRIPT.SHELL to automate command line ftp, among other
> things. Here's a snippet of code, in case it's helpful:
> ----------------------------------------
> Set oScript = Server.CreateObject("WSCRIPT.SHELL")
> '**********************************************************
> ' create command string, map path to the ftp command file
> ' created above, create temp file for logging
> '**********************************************************
> strCMD = "ftp.exe -s:" & Server.MapPath("vendor.ftp")
> strLogFile = "C:\Inetpub\wwwroot\it\transmissions\logs\vendor" &
> datDataDate & ".log"
> '**********************************************************
> ' run the command, output to the temp file, then read it
> '
> '**********************************************************
> Call oScript.Run("cmd.exe /c " & strCMD & " > " & strLogFile, 0, True)
> Set oFile = objFSO.OpenTextFile (strLogFile, 1, False, 0)
> ----------------------------------------
> joel

I've tried the above suggestion and I'm getting Permission Denied error.

Basically I want to execute a python script and capture the output. My
strCMD looks like this:

   cmd.exe /c {path_to_python_exe} {python_script} {parms} > {output_file}

This gives back a Permission Denied error. If I change it to:

   {path_to_python_exe} {python_script} {parms} > {output_file}

then there's no error, but the output file is also not written. I'm
not sure if python was actually executed. However, I'm almost sure I
have write access to the output folder since I use the same ASP script
to upload a file to that folder.

Since I'm aiming at capturing the python output, I had better luck
with the WshScriptExec object. I tried copying the code in the
following page:


With the following result:

Set oShell = CreateObject("WScript.Shell")
Set oExec  = WshShell.Exec({path_to_python_exe} {python_script} {parms})
Do While True
   If Not oExec.StdOut.AtEndOfStream Then
      Exit Do
   End If

This seems to work fine, but if you compare it to the original sample
code, I had to remove the WScript.Sleep line because it doesn't seem
to be valid in the context of ASP. I think the sleep is necessary to
make it more efficient. Is there an alternative to WScript.Sleep for
ASP pages?


More information about the thelist mailing list