Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 批处理文件未通过windows服务执行_C#_Windows Services_Selenium Rc - Fatal编程技术网

C# 批处理文件未通过windows服务执行

C# 批处理文件未通过windows服务执行,c#,windows-services,selenium-rc,C#,Windows Services,Selenium Rc,我有一个场景,其中我必须创建一个windows服务,该服务将检查批处理文件是否未运行,然后它应该执行该批处理文件 此外,我的批处理文件用于自动化,使用Selenium进行应用程序签出 当我创建该服务时,不知何故批处理文件没有执行,无法启动selenium。当我在任务管理器中看到相同的情况时,我可以看到cmd实例正在运行,但它无法运行selenium 我的项目代码:计时器设置为1分钟 private void timer1_Elapsed(object sender, System.Timers.

我有一个场景,其中我必须创建一个windows服务,该服务将检查批处理文件是否未运行,然后它应该执行该批处理文件

此外,我的批处理文件用于自动化,使用Selenium进行应用程序签出

当我创建该服务时,不知何故批处理文件没有执行,无法启动selenium。当我在任务管理器中看到相同的情况时,我可以看到cmd实例正在运行,但它无法运行selenium

我的项目代码:计时器设置为1分钟

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();
     }
}
批处理文件如下所示:

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"

此代码将定期检查,如果批处理文件未在执行中,则我的服务将开始执行,否则将不执行任何操作。

不确定,因为上下文太少。。。但我要检查的第一件事是执行bat文件的路径与bat文件使用的文件有关;如果您从另一个程序调用bat文件,它通常会从该程序继承environment文件夹,这是大多数人所不期望的。(对于windows服务,这是windows\system32)检查是否存在这种情况的最简单方法是在bat文件的第一行中显式设置路径(例如cd[bat文件的路径])

提供运行批处理文件的代码。@EstefanyVelez:我已经用我的代码更新了问题。我已经添加了windows服务的代码以及需要执行的批处理文件。