Sikuli multiple scripts batch - windows

I'm trying to create a batch in Windows 7 that will open at least two Sikuli scripts in sequence. I've tried using the solutions found here and couldn't get them to work. This is the batch command I've used:
cmd /C C:\path\Sikuli\runIDE.cmd -r C:\path\Sikuli\all.sikuli
cmd /C C:\path\Sikuli\runIDE.cmd -r C:\path\Sikuli\sikuli_test.sikuli
I've also tried:
start /i /b /wait C:\path\Sikuli\runIDE.cmd -r :\path\Sikuli\all.sikuli
start /i /b /:\path\Sikuli\runIDE.cmd -r :\path\Sikuli\sikuli_test.sikuli
The first Sikuli script executes but the second one does not. The problem seems to be within Sikuli IDE opening in cmd, which once it initializes doesn't allow any more commands in the batch to execute as Sikuli's monitoring process takes over the cmd prompt.

start /wait will wait for the executable to exit before continuing. Remove the /wait switch and batch will proceed to your second command.

have you tried
cd C:\SikuliX && runScript.cmd -r C:\path\Sikuli\all.sikuli
cd C:\SikuliX && runScript.cmd -r C:\path\Sikuli\sikuli_test.sikuli

What I did is I have two batch files to call the sikuli files ("Dummy1.sikuli" and "Dummy2.sikuli").
And then I have a 3rd batch file that will call all other batch files.
Sikuli opens by using the command window, and this way both .sikuli files have a command window.
My examples are all located in:
C:\Dummy
Files located here:
Dummy1.sikuli
Dummy2.sikuli
Dummy1.bat
Dummy2.bat
RunDummies.bat
Dummy1.bat
#ECHO OFF
REM Run Dummy1.sikuli
C:\Sikuli\runIDE.cmd -r C:\Dummy\Dummy1.sikuli
Dummy2.bat
#ECHO OFF
REM Run Dummy2.sikuli
C:\Sikuli\runIDE.cmd -r C:\Dummy\Dummy2.sikuli
RunDummies.bat
#ECHO OFF
start cmd.exe /C Dummy1.bat
start cmd.exe /C Dummy2.bat

Related

How do I load multiple programs in a Windows batch script?

I'm trying to create a batch file to load multiple Window programs, more specifically, applications that control peripheral flight hardware.
I can't seem to figure out how to open up all applications consecutively. I've tried a number of things including running the executable application:
#echo off
cd "D:\Controls\" & start "D:\HW_Controls\Control1.exe" &
cd "D:\Controls\" & start "D:\HW_Controls\Control2.exe" &
cd "D:\Controls\" & start "D:\HW_Controls\Control3.exe"
That would only run one application at a time, until I exit that application, which is what I don't want. I want them to open consecutively. So I read somewhere on StackOverflow from an old post to try running each application as its own batch file like so:
#echo off
start "D:\Controls1.bat" &
start "D:\Controls2.bat" &
start "D:\Controls3.bat"
In which each batch file within looks similar to this:
cd "D:\Controls\" & start "D:\HW_Controls\Control{1..3}.exe"
I've also tried using chdir:
chdir "D:\Controls\" & start "D:\HW_Controls\Control{1..3}.exe"
When I try to load the batch file within, it doesn't appear to change the directory, and loads only opens a command prompt where the initial batch file is located, in this case, the Desktop directory.
I know there are options to open them on Windows startup, but that's not what I want. I want to load them up when I need to use the applications.
BONUS POINTS: If someone can tell me how to exit all the applications in a batch script as well when I'm finished with them.
The batch parser works line by line. & is used to write two commands in one line. So it doesn't make sense to end a line with a &.
For readability, the use of & should be limited.
cd should be used with the /d switch to be able to switch to another drive.
start takes the first quoted parameter as a window title, so give it a pseudo title.
start has a /d parameter to set the working folder, so you don't need cd at all:
So your batch file simplifies to:
#echo off
start "" /d "D:\Controls\" "D:\HW_Controls\Control1.exe"
start "" /d "D:\Controls\" "D:\HW_Controls\Control2.exe"
start "" /d "D:\Controls\" "D:\HW_Controls\Control3.exe"
echo press any key to kill the program.
pause >nul
taskkill /im "Control1.exe"
taskkill /im "Control2.exe"
taskkill /im "Control3.exe"
Note: taskkill sends a termination signal to the application. If it does not answer correctly by closing itself, you can force-close it with the /f switch.
Here's one method to launch multiple programs at once:
#For %%A in ("notepad.exe" "chrome.exe" "calc.exe") do start "" %%~A

How to pause a batch script on a command

I have a below batch script:
#echo off
cd C:\Program Files (x86)\Project
CALL init_env.bat
cd C:\Users\Documents\Project\Release
START app.exe -ver 133
echo application has been stopped
This starts the app.exe. On the terminal it also says application has been stopped. Is there any way I can pause the script after executing the line START app.exe -ver 133 and only run echo application has been stopped when the app was closed or crashed for some reason.
Thanks
The command START should be removed because it starts the executable app.exe as separate process being executed parallel to cmd.exe processing the batch file. Then cmd.exe processing the batch file starts app.exe and waits with further processing of the batch file until app.exe terminated itself.
It is also recommended to always enclose a file/folder string in " even on not really being necessary. So cd /D "C:\Program Files (x86)\Project" and call "init_env.bat" should beĀ used or even better call "C:\Program Files (x86)\Project\init_env.bat" if that works also because of batch file init_env.bat is written to work independent on what is the current directory on execution. And last cd /D "C:\Users\Documents\Project\Release" and "app.exe" -ver 133 should be written in the batch file.
Run in a command prompt window cd /? for help on command CD and meaning of option /D.
start /? outputs the help for command START in cmd window.
#echo off
call "C:\Program Files (x86)\Project\init_env.bat"
cd /D "C:\Users\Documents\Project\Release"
"app.exe" -ver 133
echo application has been stopped
See also the predefined Windows environment variables.

How to end a batch file with an open command window at a certain folder location

This seems like it should be ridiculously simple but I cannot find the answer online or in these forums.
I want to run a command from a batch file, leave the command window open and end at a particular file location.
I can't seem to get both to happen in the same window. This is for a script to run an automated task everytime and leave the window open to run a 2nd task that has a variable input.
start cmd /k c:\users\test\desktop\dmiwtool1.1\win64\dmiwtoolx64.exe & cd c:\users\test\desktop\dmiwtool1.1\win64\
If I run either by itself, they work (runs the exe, ends at /desktop prompt), but in this sequence only the first runs.
this works here:
#ECHO OFF
START /b "" "path\program.exe" "parameter"
CD %UserProfile%\Desktop
Do not use setlocal in your Batch or put endlocal in the line before the CD command.
This should work:
start cmd /k "c:\users\test\desktop\dmiwtool1.1\win64\dmiwtoolx64.exe & cd c:\users\test\desktop\dmiwtool1.1\win64\"
If you leave out the quote marks, the start command and the cd command are run separately.

Running vbscript from batch file

I just need to write a simple batch file just to run a vbscript. Both the vbscript and the batch file are in the same folder and is in the SysWOW64 directory as the vbscript can only be execute in that directory. Currently my batch file is as follows:
#echo off
%WINDIR%\SysWOW64\cmd.exe
cscript necdaily.vbs
But the vbscript wasn't executed and just the command prompt is open. Can anyone tell me how can i execute the vbscript when i run this batch file?
You can use %~dp0 to get the path of the currently running batch file.
Edited to change directory to the VBS location before running
If you want the VBS to synchronously run in the same window, then
#echo off
pushd %~dp0
cscript necdaily.vbs
If you want the VBS to synchronously run in a new window, then
#echo off
pushd %~dp0
start /wait "" cmd /c cscript necdaily.vbs
If you want the VBS to asynchronously run in the same window, then
#echo off
pushd %~dp0
start /b "" cscript necdaily.vbs
If you want the VBS to asynchronously run in a new window, then
#echo off
pushd %~dp0
start "" cmd /c cscript necdaily.vbs
This is the command for the batch file and it can run the vbscript.
C:\Windows\SysWOW64\cmd.exe /c cscript C:\Windows\SysWOW64\...\necdaily.vbs
Just try this code:
start "" "C:\Users\DiPesh\Desktop\vbscript\welcome.vbs"
and save as .bat, it works for me
Batch files are processed row by row and terminate whenever you call an executable directly.
- To make the batch file wait for the process to terminate and continue, put call in front of it.
- To make the batch file continue without waiting, put start "" in front of it.
I recommend using this single line script to accomplish your goal:
#call cscript "%~dp0necdaily.vbs"
(because this is a single line, you can use # instead of #echo off)
If you believe your script can only be called from the SysWOW64 versions of cmd.exe, you might try:
#%WINDIR%\SysWOW64\cmd.exe /c call cscript "%~dp0necdaily.vbs"
If you need the window to remain, you can replace /c with /k
Well i am trying to open a .vbs within a batch file without having to click open but the answer to this question is ...
SET APPDATA=%CD%
start (your file here without the brackets with a .vbs if it is a vbd file)
You should put your .bat file in the same folder as your .vbs file and call the following code inside the .bat file.
start cscript C:\filePath\File.vbs

open command prompt window and change current working directory

I'm terribly new to scripting on windows. Using windows 7 64.
I'm trying to make a .bat file that I can double click, and have it open a command prompt and automatically cd me to a certain directory.
I tried making a .bat file with
#ECHO OFF
cmd "cd C:\my\destination"
Which opens what looks like a command prompt, but doesn't seem to let me type any commands.
I then tried:
#ECHO OFF
start cmd "cd C:\my\destination"
But this just sent me into a loop opening tons and tons of prompts until my computer crashed :) The .bat file was located in the destination directory if that matters.
This works for me:
#ECHO OFF
cmd.exe /K "cd C:\my\destination && C:"
The quoted string is actually two commands (separated by a double ampersand): The first command is to change to the specified directory, the second command is to change to the specified drive letter.
Put this in a batch (.BAT) file and when you execute it you should see a Command Prompt window at the specified directory.
Use the /K switch:
#ECHO OFF
start cmd.exe /K "cd C:\my\destination"
But IMHO, the most useful switch is /?.
Starts a new instance of the Windows XP command interpreter
CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
[[/S] [/C | /K] string]
/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
...
And only if it does not work, then Google it, as #Neeraj suggested :D
This could be done like that:
#ECHO OFF
cd /D "C:\my\destination"
cmd.exe
If you need to execute a file or command after you open the cmd you can just replace the last line with:
cmd.exe /k myCommand
#ECHO OFF
%comspec% /K "cd /D d:\somefolder"
The /D will change folder and drive and works on 2000+ (Not sure about NT4)
If you take a look at Vista's open command here, it uses cmd.exe /s /k pushd \"%V\" but I don't think %V is documented. Using pushd is a good idea if your path is UNC (\\server\share\folder) To get UNC current directory working, you might have to set the DisableUNCCheck registry entry...
Why so complicated? Just create an alias to cmd.exe, right click on the alias and navigate to its settings. Change the "execute in" to the path you want to have as standard path. It will always start in this path.
just open a text editor and type
start cmd.exe
cd C:\desired path
Then save it as a .bat file. Works for me.
You can create a batch file "go-to-folder.bat" with the following statements:
rem changes the current directory
cd "C:\my\destination"
rem changes the drive if necessary
c:
rem runs CMD
cmd

Resources