I have a scenario in which i have to create a windows service which will check that if the batch file is not running then it should execute that batch file.
Moreover, my batch file is used for automation using Selenium for Application checkout.
When i create that service, somehow the batch file is not executing and is not able to launch the selenium. When i see same in task manager, i can see a cmd instance is running but that cannot run my selenium.
Code of my Project: Timer is set to 1 minute
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (!File.Exists(ConfigurationManager.AppSettings["testFilePath"])) //To check whether batch file is running or not
{
System.Diagnostics.Process proc = new System.Diagnostics.Process(); // Declare New Process
proc.StartInfo.FileName = ConfigurationManager.AppSettings["BatchFilePath"];
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
}
}
Batch File is like This:
copy C:\AutomatedTests\AHD\testingWS.txt C:\AutomatedTests\AHD\AHDExecutionService\testingWS.txt
start cmd /k java -jar "C:\AHS_Automation\Release\UnifiedBillingSystem\Selenium RC\selenium-server-1.0.3\selenium-server.jar"
This code will check periodically that if batch file is not under execution then my service will start its execution otherwise will do nothing.