Why is `cmd /C` living after it did its job?

Posted on


My question is why does “cmd” exist (idle) in my process after i update my exe?

In my code i run this code to update myself and launch

var args = string.Format(@"/C ping -n 1 -w 3000 & move /Y ""{0}"" ""{1}"" & ""{1}"" {2}", updateFn, fn, exeargs);
new Process() { StartInfo = new ProcessStartInfo(@"cmd", args) { CreateNoWindow = true, UseShellExecute = false } }.Start();

The idea is i exit right away and have ping stall for 3seconds before trying to replace my current exe with my updated exe. Then i launch with the necessary args

The full arg for cmd looks like this

/C ping -n 1 -w 3000 & move /Y “c:pathupdate” “c:pathmy.exe” & “c:pathmy.exe” exeargs

Everything works fine however i see cmd in the taskmanager (looks to be idle) after my process is launched and correctly working. Why?


The last part of your argument is & "c:pathmy.exe" exeargs which causes the command-interpreter to wait for my.exe to finish running before it exits and obviously my.exe is not a program that runs and exists on its own; it is staying active.

You can use start my.exe to have the command-interpreter launch my.exe and continue on without waiting for it.

Leave a Reply

Your email address will not be published. Required fields are marked *