Parent process ends before child has completed
Silic0nS0ldier opened this issue · 2 comments
Bug description
Wrapper terminates before command completed, leaving it running in the background. Behaves similar a bash command is made to execute in the background by adding &
at the end of a command.
Reproduction steps
Wrap a script which produces a non-zero exit code (time may be a factor while the wrapper finishes up, adding a delay should help is this is the case) and run it. Check the reported exit code.
Additional context
Observed on MacOS.
Looks to be a known behaviour. https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning
On Linux there is exec
which fully replaces the existing process, killing the caller in the process.
On Windows (if I've read the docs right, I almost certainly have not) there is no equivalent to exec
, however child processes won't be closed until an explicit function is called (e.g. ExitProcess
) or the past thread in a process terminates.
Best I can tell there isn't anything in Rust standard API which covers this in a cross platform manner. child.wait()
would technically fix this, but it would also prevent stdin
usage (it gets killed to eliminate a potential deadlock). There is also try_wait
but contrary to its name its a non-blocking "are we done yet" check, a loop would be required. Shame wait
can't be used with stdin
left alone, it all comes down to literally one line.