I've a problem to kill command window launch with cmd /k. To replace in the context, i want to launch automatic tests cases (with SAHI Framework, it ressemble to Selenium for who knows). So, i've to lauch first .bat file which contains tests suites. To test a proxy need to be launched so, i need to launch everything at the same place because we packed all that thing in a Jenkins server.
So for recap I have to create a script with these steps :
Code :
rem Start proxy server for handle tests
start cmd /k sahi.bat
rem Starting test suites
testrunner.bat tests.suite http://website.fr/ firefox
So, these steps are done and works fine. But i've to close the serveur proxy opened in step-2 after step-3.
How can i kill the sahi.bat after tests cases ?
There are different ways to achieve what you are looking for. My solution:
@ECHO OFF
START "Proxy" sahi.bat
START /WAIT testrunner.bat tests.suite http://website.fr/ firefox && taskkill /FI "WINDOWTITLE eq <username>: Proxy"
START "Proxy" sahi.bat
will start a new console with your proxy. The window title will be username: Proxy. Just try to open a window with START "test" cmd if you are not sure about the window title.
Now START /WAIT "testrunner.bat tests.suite http://website.fr/ firefox" && taskkill /FI "WINDOWTITLE eq <username>: Proxy"
will do two things: it will execute your tests in a new console and kill the proxy server. &&
means that both commands will be executed one after the other. But this is not enough as your script would start the tests and instantly kill the proxy after that. To avoid this we simply add /WAIT
to our command to make the script execute the kill command as soon as the test bat terminates.
TL;DR