I have the below Delphi code to provide a friendly wrapper for the CreateProcess API call.
function StartProcess(ExeName: string; CmdLineArgs: string = \'\';
When you set ShowWindow = False
, you set the startup flags to include StartF_UseStdHandles
, but you never provide any values for the standard I/O handles. The moment the new process attempts to write any output, it will fail because it doesn't have a valid output handle.
If you're not going to provide values for the handles, then don't tell CreateProcess
that the handle fields have valid values in them. Omit that flag from the startup flags.
You don't get any error when creating the process because creating the process went fine. It's only after the process started running that it ran into problems. You're not checking the process's exit code, so there's no way you'd detect any failure.