Talk:ExecWait and waiting for child processes with Job Objects

From NSIS Wiki
Jump to navigationJump to search

This macro exits with an error message:

Plugin Command: Call kernel32::CloseHandle(i $2) Plugin Command: Call kernel32::CloseHandle(i $1) Error: unterminated string parsing line at macro:ExecWaitJob:37 Error in macro ExecWaitJob on macroline 37 Error in script "D:\Users\nlzj01t\My Documents\My Scripts\waitjob.nsi" on line 44 -- aborting creation process

--Anders 17:15, 18 March 2008 (PDT) Fixed

The fix works. This has solved a huge problem for me. Thanks for your work! = Jim


Bug fixes

I could have sworn I tried to post fixes. Did it get reverted? I can understand that but now my fixes aren't even in the history. :( I didn't end up using this macro so that code is lost now.

IIRC one of the fixes was that inserting _exec like it is doesn't work with complex strings. It is best to StrCpy it to a numbered variable first and just use the r0 syntax.

r0 syntax should also be consistently used AFAIK, if you use $0 I believe NSIS will substitute before calling the plugin, using r0 syntax ensures the plugin can understand the string it is passed (ie if $0 has commas in it the plugin could get confused surely?).

CreateProcess needs the breakaway flag that tells it to break out of a current job (otherwise assigning the process to your new job fails if the new process is already in a job, which will occur if YOUR process is in a job).

The GetQueuedCompletionStatus call passes INFINITY so there is no need for a loop, it will wait as long as it needs to. Once the call returns there's no more need for checking errors or return values, you're done either way.

This could also use better error handing (you shouldn't continue if an error occurs, you should immediately cleanup and Abort or fall through or something).

--192.91.171.36 16:18, 18 January 2012 (UTC)

I don't see any edits in the history either, did you fail the captcha or something?

The _exec / r0 issue is a good point, I'll change the sample.

Breakaway only works if the job explicitly set JOB_OBJECT_LIMIT_BREAKAWAY_OK, but I'll add the flag anyway.

The GetQueuedCompletionStatus loop is required since you get different messages but we only care about JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO.

Anders 23:36, 19 January 2012 (UTC)