How can I know when I have finished executing a cmd command from vb.net?

1

I am working with ffmpeg and I want to execute the commands from a form (vb.net) but I would like to know how I can know when that process has finished. I am currently using:

    Dim Proc As New System.Diagnostics.Process
    Proc.StartInfo = New ProcessStartInfo("C:\Windows\System32\cmd.exe")
    Proc.StartInfo.Arguments = "ffmpeg -i video.mp4 -ss 00:00:14.435 -vframes 1 out.png"
    Proc.StartInfo.RedirectStandardInput = True
    Proc.StartInfo.RedirectStandardOutput = False
    Proc.StartInfo.UseShellExecute = False
    Proc.StartInfo.CreateNoWindow = True
    Proc.Start()

How do I know when the process is over?

    
asked by Fabrizio Piminchumo 29.11.2017 в 21:03
source

1 answer

0

You have 2 options.

  • If you want your code to block until the process is finished, you can use .WaitForExit() :

    ' ...
    Proc.Start()
    Proc.WaitForExit()
    
  • If you want to receive a notification asynchronously when the process ends, you can register for the event Exited . If you do this, you must assign the property EnableRaisingEvents to True as well:

    ' ...
    Proc.EnableRaisingEvents = True
    AddHandler Proc.Exited, Sub(o, s) Console.WriteLine("El process terminó")
    Proc.Start()
    
  • Reference

        
    answered by 29.11.2017 / 21:46
    source