Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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_Process - Fatal编程技术网

C# 正在启动windows服务中不工作的进程

C# 正在启动windows服务中不工作的进程,c#,windows-services,process,C#,Windows Services,Process,我正在尝试使用进程通过c#.net执行exe文件。返回以下异常时执行失败: System.InvalidOperationException:没有进程与此对象关联。 在System.Diagnostics.Process.Ensure(状态)下 在System.Diagnostics.Process.Ensure(状态)下 位于System.Diagnostics.Process.GetProcessHandle(Int32访问,布尔throwIfExited) 在System.Diagnost

我正在尝试使用进程通过c#.net执行exe文件。返回以下异常时执行失败:

System.InvalidOperationException:没有进程与此对象关联。 在System.Diagnostics.Process.Ensure(状态)下 在System.Diagnostics.Process.Ensure(状态)下 位于System.Diagnostics.Process.GetProcessHandle(Int32访问,布尔throwIfExited) 在System.Diagnostics.Process.WaitForExit时(Int32毫秒) 在System.Diagnostics.Process.WaitForExit()中 在VideoHandlingWinService.VideoHandlingService.ConvertVideoToFlv(字符串保存路径、字符串WithOutExt、字符串输入文件、字符串spath、Int32 VideoQueueId) 在VideoHandlingWinService.VideoHandlingService.VideoHandling(字符串VideoName、字符串保存路径、字符串输入文件、字符串WithOutExt、字符串spath、Int32 VideoQueueId、字符串VideoDescription、Int32 RegisteredUserId、Int32 CategoryId、字符串VideoTitle) 在VideoHandlingWinService.VideoHandlingService.StartHandlingVideo()中 位于VideoHandlingWinService.VideoHandlingService.OnStart(字符串[]args)

我启动流程的代码如下所示:

Process proc = new Process();
string spath = AppDomain.CurrentDomain.BaseDirectory.ToString();

try
{
    proc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe";
    proc.StartInfo.Arguments = FilArgs;
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.CreateNoWindow = false;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.RedirectStandardError = true;

    proc.Start();

    string StdOutVideo = proc.StandardOutput.ReadToEnd();
    string StdErrVideo = proc.StandardError.ReadToEnd();             
}
catch { }
finally
{
    proc.WaitForExit();
    proc.Close();
}

任何人请告诉我如何在windows服务中执行此操作。另外,我正在以本地帐户运行windows服务,希望exe没有权限问题。

我认为错误发生在

proc.WaitForExit();
您确定没有执行ffmpeg吗

根据MSDN

WaitForExit()重载为 用于生成当前线程 等待关联的进程 终止。此方法指示 处理组件以等待无限长的时间 进程和进程的时间量 要退出的事件处理程序


我猜当你进入
时,ffmpeg已经退出了。

无论如何,使用
System.IO.Path.Combine(Path,“ffmpeg\\ffmpeg.exe”)
你有一个空的catch块。删除它或在其中添加一些日志记录,以便查看实际情况。可能这意味着您的空捕获吞下了一个异常,并且该进程从未执行过,这解释了错误消息…put proc.WaitForExit();过程关闭();在proc.start()之后并检查什么HPPens异常是由于我的路径引起的。对于windows服务,我无法使用根路径,因为它在外部工作。现在,我通过为spath提供完整的物理路径来消除异常。该异常是由于我的路径引起的。对于windows服务,我无法使用根路径,因为它在外部工作。现在,我通过提供spath的完整物理路径。