首页 > 解决方案 > 使用 asp classic 调用 bat 文件

问题描述

谁能帮我解决这个问题,我需要调用/执行 bat 文件。下面是我的 bat 文件和 asp 经典代码。

测试.bat

    echo off
    start C:\inetpub\wwwroot\Texting\Notification.lnk

该 test.bat 将运行快捷方式并调用应用程序,该应用程序将更新收到的文件。

sample.asp此代码适用于经典 asp

    <%

    dim fs,tfile,loc,locadd,loctime1,nameFile,wshell

    locadd = Month(Date)&Day(Date)&Year(Date)
    loctime1 =  stripNonNumeric(FormatDateTime(Now,3))
    nameFile = "\\85new\Accts85new\Texting\Reply\Karing\"
    loc = "\\85new\Accts85new\Texting\Reply\Karing\"&locadd&"_"&loctime1&".txt"
    set fs= Server.CreateObject("Scripting.FileSystemObject")
    set tfile=fs.CreateTextFile(loc)

    For Each Item in Request.QueryString
        tfile.Write Item &";"& Request.QueryString(Item)&"$&$"
    next

    tfile.close
    set tfile=nothing
    set fs=nothing

    Function stripNonNumeric(inputString)
        Set regEx = New RegExp
         regEx.Global = True
         regEx.Pattern = "\D"
         stripNonNumeric = regEx.Replace(inputString,"")
      End Function

    set wshell = CreateObject("WScript.Shell")
    wshell.Run "cmd.exe /c C:\inetpub\wwwroot\Texting\test1.bat"
    set wshell = nothing

    %>

sample.asp将从查询字符串中获取参数值。

代码正在运行,当我在浏览器上按 ENTER 时没有收到错误。

先感谢您!

标签: batch-fileiisasp-classicwindow

解决方案


通常这应该以另一种方式完成,但假设您了解从 Web 应用程序调用 bat 文件的安全含义,您需要尝试将输出重定向到文件以确保它被执行以及输出是什么,即

wshell.Run "test1.bat>debug.txt" 

CreateObject("WScript.Shell") 在单独的进程中执行,您不会在浏览器中收到任何错误,这就是您的 bat 文件需要在某处输出其结果的原因。


推荐阅读