Friday, May 9, 2008

Launching Windows Processes

The myriad of ways to launch processes on Microsoft Windows is staggering. Getting your application right is very difficult. One challenge I recently came across was a problem launching certain Microsoft command line tools. I had the same problem from both .NET (using C#) and from using the native CreateProcess Win32 API. If you are having problems with System.Diagnostics.Process or CreateProcess while trying to capture standard out and/or standard error, it very likely could be the same issue. Some of the applications that were found to have the problem were: chkntfs.exe, chkdsk.exe, xcopy.exe. As it turns out, for one reason or another for these particular applications, if you are capturing stdout or stderr, you must also give a handle for capturing stdin. Once you do that it will start working correctly.

I searched for awhile on Google and found several people who had the same problem, but never could find a satisfactory answer. Finally came up with this, so hopefully documenting it here will help others in the future.

0 comments: