views:

70

answers:

2

I have a process object setup like the following:

Process p = new Process();
p.StartInfo.FileName = command;
p.StartInfo.UseShellExecute = true;
p.StartInfo.Arguments = String.Format(
    commandArguments,
    destinationLocation,
    sourceLocation,
    sourceDirName,
    (string.IsNullOrEmpty(revisionNotes.Text)) ? "" : revisionNotes.Text);

(where undefined values are supplied externally to this code and are valid). The process in question launches and properly executes with p.Start(); but i need to catch it on termination. The console window flashes up briefly and goes away which would seem to indicate that the process is done, but none of the relevant events are fired (OutputDataRecieved, Exited, etc) and it's like the process never ends. (I'm trying to execute a lua script with some parameters if that's relevant). Can someone help me get this process to stop correctly?

+4  A: 

WaitForExit

Darin Dimitrov
short 'n sweet.
Pieter888
+2  A: 

Have you set the EnableRaisingEvents property of the process to True? You won't catch the Exited event without it.

CodeByMoonlight
Didn't know about this, thanks! i'll try it!
RCIX
Boy that's a stupid flag (at least to me), but thanks for the help this will probably be what i want!
RCIX
Darin's method is generally more suitable, unless you want to do other things while waiting for the process to end.
CodeByMoonlight
I add a lambda to the close event to do my work, so this is good for me. Besides, it lets me show a progress bar if i want.
RCIX