One option could be to run the command using 'sudo' when the 'user' parameter is set, which sets the appropriate environment variables, instead of using the gid/uid parameters to 'spawnProcess'.  In this setup, I'd probably drop the 'group' parameter, since 'sudo' does its own setting of the GID.