如何将参数从批处理传递到 vbscript?我的批处理脚本在自动执行结束时发送一封电子邮件。为此,它使用/调用我的 vbscript (email.vbs) 发送带有实际日志文件(具有执行结果)的电子邮件。所有这些日志文件都存储在特定文件夹中,例如:201207(2012 年 7 月)、201208(2012 年 8 月)等等......我想传递文件夹名称或部分(我正在考虑硬编码2012 部分并通过我的批处理从该参数中获取月份编号)它作为我的 email.vbs 的参数,以便它可以去寻找正确的文件夹来获取正确的日志文件。说得通?
ECHO Checking the log file for errors...
FINDSTR /C:"RC (return code) = 0" %workDir%\%filenm%_Log.txt && (ECHO Deployment was successful.
ECHO Email is sent out...
cscript //nologo success_mail_DEV.vbs %workDir% 'passing the directory param. here.
ECHO Press ENTER to exit...
GOTO offshore) || (ECHO Deployment was not successful. Errors were found!
ECHO Email is sent out...
ECHO Press ENTER to exit...
cscript //nologo fail_mail_DEV.vbs %workDir% 'and here
GOTO offshore)
这是我现在拥有的一部分。它正在检查日志文件中的错误并相应地调用该成功/失败邮件。现在,您在上面看到的 2 个 vbs 邮件脚本中硬编码了位置名称/编号。我确信有一种方法可以将参数传递给发送电子邮件的 vbscript。但是,我不知道该怎么做。
这是我的邮件 vbscript:
Const ForReading = 1
Set args = WScript.Arguments
directory = args.Item(0) 'thought that workDir would come in here
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(&directory&"\filename.txt", ForReading)
fileName = objTextFile.ReadLine
Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
MyTime = Now
ToAddress = "destination@email.com"
MessageSubject = "SUCCESS"
MessageBody = "It was successful"
MessageAttachment = &directory&"\"&fileName&"_Log.txt"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
objTextFile.Close
但不工作...
提前致谢!