SERVER-18877 added the ability for _startMongoProgram() to accept an object describing the desired environment for the program being run.
However, _startMongoProgram() starts the program asynchronously, and there are times when it would be useful to set the environment for a program that is run synchronously with runProgram().
In this case it's not possible to use _startMongoProgram instead, because although it returns a pid, there is no way to wait for that pid to exit. stopMongoProcessByPid() is the close (since it takes a pid instead of a port), but it it structured such that it sends a signal (SIGTERM by default) to the process, and elevates that to SIGKILL if the process doesn't exit after a minute.
A workaround is to use waitProgram(), which is only slightly ugly:
It would be nicer if runProgram() supported the same dual calling convention as _startMongoProgram, ie: