0

Inside of Hyperion Reporting Studio I have a document level script where I wish to call a batch file and pass arguments to the batch file.

Here is the code I have:

var Path = "W:\\directory\\Reference_Files\\scripts\\vbs\\SendEmail.bat"
var Email = "my.email@xxx.com"
var Subject = "My Subject"
var Body = "My Body"
var Attach = "W:\Maughan.xls"

Application.Shell(Path + " " + Email + " " + Subject + " " + Body + " " + Attach)

This code does not open the file, but gives the error message The filename, directory name, or volume label syntax is incorrect.

If I pass Path by itself my bat file runs (giving me a warning because no parameters are passed) and I when I run the same code from the Shell Command, it works flawlessly.

Can anyone provide any insight into the correct syntax to pass into the Application.Shell method so that it reads my parameters and passes them to the batch file? I have been searching high and low online to no avail.

4

2 回答 2

2

Because var Attach = "W:\Maughan.xls" should be var Attach = "W:\\Maughan.xls".

Within a string the escape character \ just escapes the next character so Attach will contain just W:Maughan.xls. To add \ you need to use \ twice.

Update:

It may have no difference in this particular case, because W:Maughan.xls means to look for Maughan.xls in the current directory on the drive W which is most likely \.

But what is definitely important are quotes around the parameters Subject and Body. In you code the constructed command is

W:\directory\Reference_Files\scripts\vbs\SendEmail.bat my.email@xxx.com My Subject My Body W:Maughan.xls

I sure that the bat file cannot distinguish between the subject and body (unless it expect exactly two words in each of them) so the right command most likely is

W:\directory\Reference_Files\scripts\vbs\SendEmail.bat my.email@xxx.com "My Subject" "My Body" W:\Maughan.xls

and you can check it by running the command above in cmd.

To construct it the parameters should be modified as follows:

var Path = "W:\\directory\\Reference_Files\\scripts\\vbs\\SendEmail.bat"
var Email = "my.email@xxx.com"
var Subject = "\"My Subject\""
var Body = "\"My Body\""
var Attach = "W:\\Maughan.xls"

(this correction was inspired by impinball's answer)

于 2013-11-14T21:57:30.280 回答
2

Try putting an escaped quote on either side of the variable values. Depending on where the directory is, that may make a difference. The outside quotes in strings aren't included in the string values in JavaScript. Here's an example of what I'm talking about:

var Path = "\"W:\\directory\\Reference_Files\\scripts\\vbs\\SendEmail.bat\""

instead of

var Path = "W:\\directory\\Reference_Files\\scripts\\vbs\\SendEmail.bat"
于 2013-11-14T23:42:33.220 回答