【发布时间】:2010-11-23 10:14:45
【问题描述】:
我正在尝试使用进程通过 c#.net 执行 exe 文件。执行失败,返回以下异常:
System.InvalidOperationException:没有进程与此对象关联。 在 System.Diagnostics.Process.EnsureState(状态状态) 在 System.Diagnostics.Process.EnsureState(状态状态) 在 System.Diagnostics.Process.GetProcessHandle(Int32 访问,布尔 throwIfExited) 在 System.Diagnostics.Process.WaitForExit(Int32 毫秒) 在 System.Diagnostics.Process.WaitForExit() 在 VideoHandlingWinService.VideoHandlingService.ConvertVideoToFlv(字符串 SavePath,字符串 WithOutExt,字符串 InputFile,字符串 spath,Int32 VideoQueueId) 在 VideoHandlingWinService.VideoHandlingService.VideoHandling(字符串 VideoName,字符串 SavePath,字符串 InputFile,字符串 WithOutExt,字符串 spath,Int32 VideoQueueId,字符串 VideoDescription,Int32 RegisteredUserId,Int32 CategoryId,字符串 VideoTitle) 在 VideoHandlingWinService.VideoHandlingService.StartHandlingVideo() 在 VideoHandlingWinService.VideoHandlingService.OnStart(String[] 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 没有权限问题。
【问题讨论】:
-
你有一个空的 catch 块。删除它或在其中添加一些日志记录,以便您了解实际情况。
-
可能是你的空catch吞了一个异常,进程从未执行过,解释错误信息...
标签: c# windows-services process