Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
bismart
Creator
Creator

Calling a DOS batch file from macro passing a parameter

Can anyone suggest a method whereby I can call a dos batch file with a parameter from a macro?

3 Replies
Not applicable

Wow, this is a tricky one. You can use a QlikView trigger to execute an external file. You may get a prompt if you're not overriding Launch security (Security tab of User Preferences).

I tried setting this up with a simple bat file, but QlikView does not seem to be passing the parameters correctly to that file. I also tried creating a Wscript Shell inside a macro, but QlikView doesn't seem to allow that. I created a separate vbs (VBScript) file and that allowed me to create the shell. With the vbs, I set it up to take a parameter and then call my batch file, passing that parameter. I tried launching the vbs directly from within QlikView but it didn't work.

I finally came up with a solution and it seems to be a lot of work:
1. Create your batch file as normal to take a parameter. For my testing, I used:

@echo %1
pause

2. Create a vbs file which takes a parameter and runs the batch file using the parameter. I used:
Dim obj
Set obj = CreateObject("WScript.Shell")
Set oArgs = wscript.Arguments
obj.Run "c:\test.bat " & oArgs(0), , TRUE

3. In QlikView, set up your trigger to launch the vbs file. I used a button. Since I couldn't get the Trigger to work for the bat or vbs, I used cscript*.
Actions: Launch
Application: cscript
Filename: c:\test.vbs fun

That Trigger should pass the parameter, fun, to the vbs file, which will pass the parameter to the batch file and execute. Note: You can make the Filename an expression if your parameter needs to be dynamic. Here's a screenshot of the Trigger using a QlikView variable, vParam, for the parameter:

* Cscript info from Microsoft: http://technet.microsoft.com/en-us/library/bb490816.aspx

bismart
Creator
Creator
Author

Thanks for that comprehensive answer. Much appreciated.

Will try it tomorrow and let you know how I got on.

Cheers

Not applicable

Question: will the call to the batch command in Qv script help?

It will be much easier to call batch with parameter in QV.