How to run .qvw (qlikview) file through Jenkins - windows

I want to run .qvw file through Jenkins.
To Run a qlikview file I am using batch file it is working fine ,I am using below command in batch file
"path\qv.exe" /r "path\myapplication.qvw"
This command is reloading my application ,I want to do it by Jenkins.
Has anyone done this before.
When I am trying to run above batch command through jenkins job it is continuously running.
"path\qv.exe" /r "path\myapplication.qvw"

Probably it remains open. You can try to add trigger to run macro which close app after reload:
VBScript Macro to save and close app is:
sub SaveQuit
ActiveDocument.Save
ActiveDocument.GetApplication.Quit
end sub
If you are using QlikView server/publisher better use reload from QMC there.

One option may be to have VBS for opening, reloading, saving and closing, like OpenSaveClose.vbs provided below.
Then you can use it in CMD files: wscript OpenSaveClose.vbs QvDoc.qvw
REM OpenSaveClose.vbs
Dim MyApp, MyDoc
Set MyApp = CreateObject("QlikTech.QlikView")
Set MyDoc = MyApp.OpenDocEx(Wscript.Arguments.Item(0),0,False)
MyDoc.GetApplication.WaitforIdle
REM MyDoc.Reload or whatever
MyDoc.SaveAs(Wscript.Arguments.Item(0))
MyDoc.GetApplication.WaitforIdle
MyDoc.CloseDoc
MyApp.Sleep 2000
MyApp.Quit
Set MyDoc = Nothing
Set MyApp = Nothing

Related

How to run .Bat file in background

I need to print the pdf file from the browser, so I have created a custom URL protocol to trigger the bat file, now I need to prevent the command prompt window from opening, also I need to protect the bat file from editing from the user side.
Open notepad and add the below content to it, then save the file as hidebatch.vbs:
echo Set MyScript = CreateObject("WScript.Shell")
echo MyScript.Run "C:\Path\to\your\batchfile.bat", 0, False
Simply replace C:\Path\to\your\batchfile.bat with the path to your batchfile. Then to launch this, instead of statring up your batchfile, you would run cscript hidebatch.vbs

nircmd: I can't run another batch file with nircmd.exe?

I have wrote a batch file that i want to run another program with nircmd.exe. But the problem is i can't run it? The batch file(Matrix.bat) runs correctlyby double-click it. But when i trying to open it with nircmd.exe, it doesn't run? why?
i tried two method:
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
start %INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
%INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
The exec command in nircmd does not run batch files but executable files. Change your code to
start "" "%INSTALLPATH%\nircmd.exe" exec show "%comspec%" "%INSTALLPATH%\Matrix.bat"
Now, nircmd executes a cmd instance that will handle the batch file execution
The problem was in path of nircmd.exe. I set path of nircmd but i didn't know why it isn't work correctly? with "pushd" command i set the path of cmd into where nircmd.exe exist. and Bow!!! everything works cerrectly. Maybe a syntax problem. If everyone know that say it here.
SET INSTALLPATH=d:\atlantic
pushd %INSTALLPATH%
nircmd exec show Matrix.bat

Run a batch file from Task Scheduler is not working with a java command

Run a batch file from Task Scheduler is not working with a java command inside the .bat file. If I run the .bat file manually its working good.
Here is the simple .bat file I'm trying to schedule
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_24;
set CMD= "%JAVA_HOME%\bin\java" -version
echo %CMD%
%CMD%
When you type batchfile.bat on the command line, you are telling cmd.exe to read the file and execute each line it finds in it. When you double-click on your batch file in explorer, it calls cmd.exe for you, after reading the file associations in the registry.
Task Manager is not so kind.
So for your task to work, schedule it like this (from memory, not on a Windows box right now) :
cmd /c "c:\full\path\to\your\batchfile.bat"
For extra robustness, you could make sure you batch file run from a known directory, like the one that it reside in, by adding this at the top:
pushd %~dp0
REM .... The original batch file goes here ....
popd
And finally you could disable CMD autorun entry by adding /d right after cmd like this:
cmd /d /c "c:\full\path\to\your\batchfile.bat"
If ixe013's suggestion doesnt work go to
'Actions'
'Edit' the task
'Start in (optional):' Put the path to the directory where the script is
So for the last one if you have 'C:\Users\Desktop\script.py' just put in 'C:\Users\Desktop\' in the 'Start in (optional):' field
What worked for me was running the task as "Users" ( computername\Users ). Once I did that, and "run with highest privileges" checked, it ran without a hitch.
Giving the full path of java.exe in the batch file fixed it for me. In a notepad, I typed the following line:
"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" -jar "C:\Users\usernameXXXX\Documents\NetBeansProjects\JavaApplication5\dist\JavaApplication5.jar"
Save this as a app1.bat file (C:\temp\app1.bat)
In the Actions tab of the task scheduler, give the path to the batch file, i.e, C:\temp\app1.bat
Also, be careful in the Conditions tab of task scheduler- make sure you uncheck "Start the task only if the computer is on AC power"
All other ways did not work for me, I followed this guide:
http://richardstk.com/2012/06/15/scheduled-task-to-run-a-batch-file/#comment-6873
In order to get the batch file to run, I had to set the "Program\script" box to contain just the name of the script (ie. script.bat) and set the the folder path of the script in the "Start in (optional)" box
I gave full permission to user Everyone from security tab from Properties of the folder in which batch file is. and it started working.
What a coworker discovered on something he had that wasn't working, and I have verified on the system I had that wasn't working is the following:
When the whole task is initially setup, you HAVE TO initially use the radio button "Run only when user is logged on". It will ask for your password for the change.
Now run the task.
Verify that whatever the batch was supposed to do, did happen.
And THEN change to the radio button BACK TO 'Run whether user is logged on or not."
This solved a problem for both of us that we had individually been working on for hours.
Side notes: both issues were also trying to elicit a 3rd party FTP app (WinSCP and WinFTP respectively) in each of our cases. Regular "inhouse" batch/tasks were having no issues.
I had the same problem, and to solve it, I put the next command line into the batch file:
cd "CURRENT_DIRECTORY"
where CURRENT_DIRECTORY is the directory where the batch file is located.
Example:
Suppose i have my batch file named test.bat located into c:\windows\system32\mytest
in my test.bat file, i introduce the next command line:
cd c:\windows\system32\mytest

vbs scheduled path not found

I cannot figure out what I'm doing wrong.
I have a batch file starting a vbs script.
The script just makes some operations in some files, like moving them, create, delete...
It works fine.
Executing the bat it starts the vbs script and everything work.
The bat file just makes a cscript file.vbs
The problem is that I've scheduled this bat file .
When the times come, it gets executed but I get the error "path not found" in the vbs script.
It's not a schedule task problem because I've 11 task running batch files and they run smootly, and the script is executed (I've put controllers on it).
But the vbs script returns always the same path not found error.
Again,if I execute the script manually, it runs without problems.
The task is scheduled with the same account I use to manual execute the file, so it's not a permission issue. I just doubleclick the batch and it runs, click on execute on the task schedule manager and it fails.
The system is windows server 2008 r2 standard.
I already tried to reboot, deleting and making a new task....
Thanks to everyone
[UPDATE]
I paste here part of the code
FILE: D:\scripts\conf.ini
[script1]
fileA=D:\Rep\exportA.csv
fileB=D:\Rep\exportB.csv
fileC=D:\Rep\exportC.csv
dirHistory=D:\Rep\history
FILE: D:\scripts\merge.vbs
Dim iniObj
Set iniObj=New ClsINI
If iniObj.OpenINIFile("D:\scripts\conf.ini") = False Then
wLog("Impossible to read file ini")
Set iniObj = Nothing
Chiudi()
End If
Dim errIni,tmpVal
Dim fileA,fileB,fileC,dirHistory
errIni = iniObj.GetINIValue("script1", "fileA", fileA)
tmpVal = iniObj.GetINIValue("script1", "fileB", fileB)
errIni = errIni+tmpVal
tmpVal = iniObj.GetINIValue("script1", "fileC", fileC)
errIni = errIni+tmpVal
tmpVal = iniObj.GetINIValue("script1", "dirHistory", dirHistory)
errIni = errIni+tmpVal
If errIni > 0 Then
wLog("Error loading file ini")
wLog(errIni)
iniObj.CloseINIFile()
Set iniObj = Nothing
Chiudi()
End If
wLog("File ini Caricato")
Dim objFso,posizioneFile,Fase
Dim arrElement,resArray,actionArray,cedoleArray,varArray ,i
Dim conn,rs,strCon
Dim maxPos,maxTemp
Dim objExcel, objSheet,cella
Set objFso = CreateObject("Scripting.FileSystemObject")
if objFso.FileExists(fileA) then
objFso.DeleteFile(posizione)
wLog("File posizione moved")
else
wLog("File posizione not found")
end if
At this line a get the error of "Path not found"
Set posizioneFile = objFso.OpenTextFile(fileA, 8, True)
If not objFso.FileExists(fileB) then
SendEmail("nego")
Fase=false
Else
Set tFile = objFso.OpenTextFile(fileB, 1)
strFile=tFile.ReadAll
tFile.Close
posizioneFile.WriteLine strFile
objFso.MoveFile fileB, dirHistory&"\Negoz_"& CreaId(2) & ".csv"
End If
posizioneFile.Close
FILE: D:\scripts\merge.bat
echo Start Merge %date% %time% >> Started.log
cscript D:\scripts\merge.vbs
Sorry if I didn't put it before, but I was thinking it was a windows issue, because I thought the code was fine.
Thanks
This sounds like an issue with the working directory although it's a bit difficult to tell, since you chose not to show the content of the batch script. If you start the script manually (by double-clicking), the working directory is the directory in which the batch script (and probably the VBScript as well) resides. If you run the batch script as a scheduled task, the working directory is %SystemRoot%\system32 unless you expressly set a working directory in the task's properties.
Now, if your batch script looks like this:
cscript.exe your.vbs
it will look for your.vbs in the working directory and won't find it if the working directory is not the directory containing your.vbs. If my assumption that both scripts are in the same directory is correct you could either set the working directory in the properties of the scheduled task or (better) change the batch script to something like this:
cscript.exe "%~dp0your.vbs"
%0 is the path to the batch script itself as it was called. %~dp0 expands %0 to the absolute path of the parent directory (including a trailing backslash).

Hide Command Window of .BAT file that Executes Another .EXE File

This is a batch file in Windows.
Here is my .bat file
#echo off
copy "C:\Remoting.config-Training" "C:\Remoting.config"
"C:\ThirdParty.exe"
This works fine except the .bat file leaves the command window open the whole time the "ThirdParty" application is running.
I need the command window to close.
I would use the short-cut for the application but I must be able to run this copy command first (it actually changes which data base and server to use for the application).
The ThirdParty application does not allow the user to change the source of the db or the application server.
We're doing this to allow users to change from a test environment to the production environment.
Using start works for me:
#echo off
copy "C:\Remoting.config-Training" "C:\Remoting.config"
start C:\ThirdParty.exe
EDIT: Ok, looking more closely, start seems to interpret the first parameter as the new window title if quoted. So, if you need to quote the path to your ThirdParty.exe you must supply a title string as well.
Examples:
:: Title not needed:
start C:\ThirdParty.exe
:: Title needed
start "Third Party App" "C:\Program Files\Vendor\ThirdParty.exe"
Create a .vbs file with this code:
CreateObject("Wscript.Shell").Run "your_batch.bat",0,True
This .vbs will run your_batch.bat hidden.
Works fine for me.
Using start works fine, unless you are using a scripting language. Fortunately, there's a way out for Python - just use pythonw.exe instead of python.exe:
:: Title not needed:
start pythonw.exe application.py
In case you need quotes, do this:
:: Title needed
start "Great Python App" pythonw.exe "C:\Program Files\Vendor\App\application.py"
Try this:
#echo off
copy "C:\Remoting.config-Training" "C:\Remoting.config"
start C:\ThirdParty.exe
exit
Great tip. It works with batch files that are running a java program also.
start javaw -classpath "%CP%" main.Main
You might be interested in trying my silentbatch program, which will run a .bat/.cmd script, suppress creation of the Command Prompt window entirely (so you won't see it appear and then disappear), and optionally log the output to a specified file.
Or you can use:
Start /d "the directory of the executable" /b "the name of the executable" "parameters of the executable" %1
If %1 is a file then it is passed to your executable. For example in notepad.exe foo.txt %1 is "foo.txt".
The /b parameter of the start command does this:
Starts an application without opening a new Command Prompt window. CTRL+C handling is ignored unless the application enables CTRL+C processing. Use CTRL+BREAK to interrupt the application.
Which is exactly what we want.
I haven't really found a good way to do that natively, so I just use a utility called hstart which does it for me. If there's a neater way to do it, that would be nice.
Using Windows API we can start new process, a console application, and hide its "black" window. This can be done at process creation and avoid showing "black" window at all.
In CreateProcess function the dwCreationFlags parameter can have CREATE_NO_WINDOW flag:
The process is a console application that is being run
without a console window. Therefore, the console handle
for the application is not set. This flag is ignored if
the application is not a console application
Here is a link to hide-win32-console-window executable using this method and source code.
hide-win32-console-window is similar to Jamesdlin's silentbatch program.
There is open question: what to do with program's output when its window does not exist? What if exceptions happen? Not a good solution to throw away the output. hide-win32-console-window uses anonymous pipes to redirect program's output to file created in current directory.
Usage
batchscript_starter.exe full/path/to/application [arguments to pass on]
Example running python script
batchscript_starter.exe c:\Python27\python.exe -c "import time; print('prog start'); time.sleep(3.0); print('prog end');"
The output file is created in working directory named python.2019-05-13-13-32-39.log with output from the python command:
prog start
prog end
Example running command
batchscript_starter.exe C:\WINDOWS\system32\cmd.exe /C dir .
The output file is created in working directory named cmd.2019-05-13-13-37-28.log with output from CMD:
Volume in drive Z is Storage
Volume Serial Number is XXXX-YYYY
Directory of hide_console_project\hide-win32-console-window
2019-05-13 13:37 <DIR> .
2019-05-13 13:37 <DIR> ..
2019-05-13 04:41 17,274 batchscript_starter.cpp
2018-04-10 01:08 46,227 batchscript_starter.ico
2019-05-12 11:27 7,042 batchscript_starter.rc
2019-05-12 11:27 1,451 batchscript_starter.sln
2019-05-12 21:51 8,943 batchscript_starter.vcxproj
2019-05-12 21:51 1,664 batchscript_starter.vcxproj.filters
2019-05-13 03:38 1,736 batchscript_starter.vcxproj.user
2019-05-13 13:37 0 cmd.2019-05-13-13-37-28.log
2019-05-13 04:34 1,518 LICENSE
2019-05-13 13:32 22 python.2019-05-13-13-32-39.log
2019-05-13 04:55 82 README.md
2019-05-13 04:44 1,562 Resource.h
2018-04-10 01:08 46,227 small.ico
2019-05-13 04:44 630 targetver.h
2019-05-13 04:57 <DIR> x64
14 File(s) 134,378 bytes
3 Dir(s) ???,???,692,992 bytes free
Example shortcut for running .bat script
Target field:
C:\batchscript_starter.exe C:\WINDOWS\system32\cmd.exe /C C:\start_wiki.bat
Directory specified in Start in field will hold output files.
You can create a VBS script that will force the window to be hidden.
Set WshShell = WScript.CreateObject("WScript.Shell")
obj = WshShell.Run("""C:\Program Files (x86)\McKesson\HRS
Distributed\SwE.bat""", 0)
set WshShell = Nothing
Then, rather than executing the batch file, execute the script.
run it under a different user. assuming this is a windows box, create a user account for scheduled tasks. run it as that user. The command prompt will only show for the user currently logged in.
Compile the batch file to an executable using Batch2Exe http://www.f2ko.de/programs.php?lang=en&pid=b2e.
Use the "Invisible Window" option.
To make the command window of a .bat file that executes a .exe file exit out as fast as possible, use the line #start before the file you're trying to execute. Here is an example:
(insert other code here)
#start executable.exe
(insert other code here)
You don't have to use other code with #start executable.exe.
I used this to start a cmd file from C#:
Process proc = new Process();
proc.StartInfo.WorkingDirectory = "myWorkingDirectory";
proc.StartInfo.FileName = "myFileName.cmd";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
Please use this one, the above does not work. I have tested in Window server 2003.
#echo off
copy "C:\Remoting.config-Training" "C:\Remoting.config"
Start /I "" "C:\ThirdParty.exe"
exit
So below vbscript will launch the cmd/bat file in hidden mode.
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
'MsgBox(strFolder)
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & strFolder & "\a.bat" & Chr(34), 0
Set WshShell = Nothing
Now, only app window will be visible, not the cmd.exe window
This is an easy work around for those who are fine with a dirty solution. Press win+tab, drag and drop the bat file to a new desktop and forget about it.
I occasionally will make a bat file that I'll rarely use, and it is kind of a drag to have to use tools to make the window hidden. This is no more complicated than it needs to be for me.

Resources