0

I am using a VBScript file named BrowserError.vbs which is accepting one argument from the Java class am using. The vbs file is used send an email when there is a test case failure with a screenshot.

Problem:

If I run the vbs file from command prompt it works fine and sends the email with attachment.

But if I run from the Java class it gives the following error:

No Script engine for .vbs TL02_Validate_ChaterInvalidLogin-1-11Apr16_045433

BrowserError.vbs:

Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim name
Dim folder
Dim displayMsg

Dim ol, ns, newMail

name = WScript.Arguments.Item(0)
FromAddress = "abc@def.com"
ToAddress = "abc@def.com"
CcAddress = "abc@def.com"
MessageSubject = "Sanity Error Alert !!!"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
MessageAttachment = "C:\Users\****\Desktop\********\CnetWorkSpaceBranch\SanityBranch\target\surefire-reports\html\screenshots\" & name & ".png"
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(MessageAttachment, 1)
strFileText = "Hi, Error notification on Sanity- User has encountered problem  : Refer screenshot "
objFileToRead.Close
Set objFileToRead = Nothing
newMail.Subject = MessageSubject & Now
newMail.HTMLBody  = strFileText
newMail.To = ToAddress
newMail.CC = CcAddress
newMail.Display
newMail.Attachments.Add(MessageAttachment).Displayname = "Check this out"
newMail.Send
Set ol = Nothing

The Java code which is used to pass the argument is like this:

String tnm="TL02_Validate_ChaterInvalidLogin-1-11Apr16_045433";
Runtime.getRuntime().exec("wscript C:/BrowserError.vbs"+tnm);

My core interest is to just send the email and get the value from the Java class while running and sending the email.

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
user3499450
  • 49
  • 1
  • 3
  • 8
  • 2
    In Java, it appears to a vbs programmer, that there should be a space after `.vbs`. The error message says it is trying to execute a script with an extension of `vbsTL02_Validate_ChaterInvalidLogin-1-11Apr16_045433` of which there isn't one. –  Apr 11 '16 at 14:04
  • See this [Stackoverflow Q&A](http://stackoverflow.com/questions/17757248/error-there-is-no-script-engine-for-file-extension-vbs-when-using-git-bash) and perhaps [this](http://www.winhelponline.com/blog/error-there-is-no-script-engine-for-file-extension-when-running-vbs-files/). My advice (and Stackoverflow rules) is that you google the error message before posting. Otherwise things get cluttered with redundent low nurishment posts. If my pointers do not help let me know. – MikeJRamsey56 Apr 11 '16 at 14:07

1 Answers1

0

As @Noodles pointed out in his comment to your question, you're appending the argument directly to the script path, thus creating an unrecognized extension.

Change this:

Runtime.getRuntime().exec("wscript C:/BrowserError.vbs"+tnm);

into this:

Runtime.getRuntime().exec("wscript C:/BrowserError.vbs "+tnm);
//                                                    ^

and the problem will disappear.

Community
  • 1
  • 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • i added a space in between .vbs and the arg[0]. now it is working fine. Runtime.getRuntime().exec("wscript C:/BrowserError1.vbs"+" "+referScreenshot+" "+test_case_name); – user3499450 Apr 12 '16 at 16:21