Patch by lukexi.

Fixing #8217 for the unix(-like) case.