0

I was running some exe with ProcessStartInfo

ProcessStartInfo startInfo = new ProcessStartInfo("my.exe");
startInfo.Arguments = "foo.txt bar.txt";
startInfo.WorkingDirectory = path;
Process process = Process.Start(startInfo);
process.WaitForExit();

It was working fine on my PC, but when I move the code to another PC, the same code keep hanging. After some trying, I was able to fix it by setting UseShellExecute to false (and use absolute path for the exe filename).

ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(Server.MapPath(@"~\mypath"),"my.exe"));
startInfo.Arguments = "foo.txt bar.txt";
startInfo.UseShellExecute = false;
Process process = Process.Start(startInfo);
process.WaitForExit();

The question is why? Why does using shell hang the process? What is the difference between using or not using shell to execute?

Thanks for the help!

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
sean
  • 1

0 Answers0