0
我们在经典ASP页面中使用vbscript,并在该vbscript中使用Wscript调用Powershell。我想检查回报,因为它是为了告诉我Powershell是否成功完成。我在Powershell脚本中有一个返回值。我已经尝试了objShell.Run和objShell.Exec,并且都没有让Powershell返回值通过我的ASP页面。使用Wscript运行powershell脚本的vbscript - 需要从powershell返回
我的问题:如何从Powershell获取返回值?
的VBScript如下:
'call PowerShell script with filename and printername and scriptname
strScript = Application("EnvSvcsPSScript")
Set objShell = CreateObject("Wscript.Shell")
dim strCommand
strCommand = "powershell.exe -file " & strScript & " " & strFileName & " " & strPrinterName
Set strPSReturn = objShell.Run(strCommand, 0, true)
response.Write("return from shell: " & strPSReturn.StdOut.ReadAll & "<br>")
response.Write("return from shell: " & strPSReturn.StdErr.ReadAll & "<br>")
PowerShell脚本:
$FileName = $args[0]
$PrinterName = $args[1]
$strReturn = "0^Successful"
"Filename: " + $FileName
"Printer: " + $PrinterName
try
{
get-content $FileName | out-printer -name $PrinterName
[gc]::collect()
[gc]::WaitForPendingFinalizers()
}
catch
{
$strReturn = "1^Error attempting to print report."
}
finally
{
}
return $strReturn
THANK YOU!
尝试了什么已提供,但是,当我尝试使用“WScript.Echo ret”显示返回值时出现以下错误:microsoft vbscript运行时错误'800a01a8'所需的对象'' – LReeder14
@ user3567046 VBScript代码太短,我不知道会出现什么问题。 我唯一的猜测是缺少的对象是'oShell',并且'Set oShell = WScript.CreateObject(“WScript.Shell”)中有一些''也许是一个错字? 请仔细检查您的代码或提供完整的命令和代码清单。 – Emons