CreateProcess returns immediately, but only if the started process is hidden

前端 未结 1 365
日久生厌
日久生厌 2021-01-07 05:52

I have the below Delphi code to provide a friendly wrapper for the CreateProcess API call.

function StartProcess(ExeName: string; CmdLineArgs: string = \'\';         


        
相关标签:
1条回答
  • 2021-01-07 06:16

    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.

    0 讨论(0)
提交回复
热议问题