Reputation: 278
I've a batch script which calls a vbs file to do some operations on a web page. From this batch file, I pass 4 parameters(string) to vbs file.
Now I'm looking to integrate this with my QTP framework.
So I need to call this batch file from framework and I'll pass these parameters from QTP to Batch file which batch file will further pass to vbs code.
Here is what I'm trying:
QTP Code:
Dim BatchRun
Set BatchRun = CreateObject ("WSCript.shell")
lob=DataTable("LOB",IntSheetNo-1)
mailto=DataTable("EmailTo",IntSheetNo-1)
mailcc=DataTable("EmailCC",IntSheetNo-1)
BatchRun.Run "C:\invoke.bat " & lob & " " & mailto & " " & mailcc
Set BatchRun = Nothing
Batch Code:
C:
cscript kamal.vbs %1 %2 %3
vbs code :
Set args = Wscript.Arguments ' to accept command line arguments
xprod = args(0)
mailto=args(1)
mailcc=args(2)
And I used these for some operations through vbs.
I did search on google and stackoverflow to find spome examples but none worked for me so far.
Upvotes: 2
Views: 2384
Reputation: 70933
Not sure what QTP is, and assuming DataTable(....) returns a string, your problem probably is the spaces in data. When calling a batch file, parameter separation is determined by spaces. If there are any space in lob, mailto or mailcc, arguments are not correctly parsed. You need to wrap each of the arguments in quotes (and ensure inner quotes in arguments are escaped to no interfere)
So, QTP
lob= Chr(34) + Replace(DataTable("LOB",IntSheetNo-1), Chr(34), Chr(34)+Chr(34)) + Chr(34)
mailto=Chr(34) + Replace(DataTable("EmailTo",IntSheetNo-1), Chr(34), Chr(34)+Chr(34)) + Chr(34)
mailcc=Chr(34) + Replace(DataTable("EmailCC",IntSheetNo-1), Chr(34), Chr(34)+Chr(34)) + Chr(34)
Dim BatchRun
Set BatchRun = CreateObject ("WSCript.shell")
BatchRun.Run "C:\invoke.bat " & lob & " " & mailto & " " & mailcc
Set BatchRun = Nothing
Batch Code
C:
cscript kamal.vbs "%~1" "%~2" "%~3"
And VBS code without changes
Upvotes: 2