Starting a process not working in my windows service
I am trying to execute an exe file through c#.net using a process. It fails to execute returning the following exception:
System.InvalidOperationException: No process is associated with this object. at System.Diagnostics.Process.EnsureState(State state) at System.Diagnostics.Process.EnsureState(State state) at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited) at System.Diagnostics.Process.WaitForExit(Int32 milliseconds) at System.Diagnostics.Process.WaitForExit() at VideoHandlingWinService.VideoHandlingService.ConvertVideoToFlv(String SavePath, String WithOutExt, String InputFile, String spath, Int32 VideoQueueId) at VideoHandlingWinService.VideoHandlingService.VideoHandling(String VideoName, String SavePath, String InputFile, String WithOutExt, String spath, Int32 VideoQueueId, String VideoDescription, Int32 RegisteredUserId, Int32 CategoryId, String VideoTitle) at VideoHandlingWinService.VideoHandlingService.StartHandlingVideo() at VideoHandlingWinService.VideoHandlingService.OnStart(String[] args)
My code to start the process is as follows:
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();
}
Any one please tell me how to do this w开发者_开发知识库ithin windows service. Also i am running the windows service as local account and hope there is no permission issue for the exe.
Anyway use System.IO.Path.Combine(path, "ffmpeg\\ffmpeg.exe")
I think the error happens in
proc.WaitForExit();
Are you sure ffmpeg is not executed?
According to MSDN
The WaitForExit()()() overload is used to make the current thread wait until the associated process terminates. This method instructs the Process component to wait an infinite amount of time for the process and event handlers to exit.
and my guess is by the time you are in finally
() ffmpeg has already exited.
精彩评论