Reputation: 569
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.
Upvotes: 0
Views: 1139
Reputation: 31116
Not sure with so little context... but the first thing I would check is the path that executes the bat file with respect to the files that the bat file uses; if you're calling the bat file from another program, it normally inherits the environment folder from that program - which is something that most people don't expect. (for a windows service this is windows\system32) The easiest way to check if this is the case is by setting the path explicitly in the first line of the bat file (e.g. cd [path of bat file] )
Upvotes: 1