src/index.js
function spawnProcess (command, args, {env = {}} = {}) {
	return Async.Promise( (resolve, reject) => {

		//debug.log('command = ', command);
		//debug.log('args = ', args);
		//debug.log('options = ', options);

		// NOTE! If you set stdout to be captured instead of ignored (the postgres log is there),
		// pgctl start will fail to exit.

		const options = {
			env: merge(process.env, env || {}),
			detached: true,
			stdio: ["ignore", "ignore", "pipe"]
		};

		let stderr = '';

		// Run the process

		//debug.log('Executing command ', command, args);

		let proc = child_process.spawn(command, args, options);

		// Handle exit
		proc.on('close', retval => {
			//debug.log('Command ', command, args, ' closed with ', retval);
			if (retval === 0) {
				resolve(retval);
			} else {
				reject({retval, stderr});
			}
		});

		// Handle error
		proc.on('error', err => {
			reject(err);
		});

		//proc.stdout.setEncoding('utf8');
		//proc.stdout.on('data', data => {
		//	process.stderr.write(data);
		//});

		proc.stderr.setEncoding('utf8');
		proc.stderr.on('data', data => {
			stderr += data;
		});

	});
}
function spawnProcess (command, args, {env = {}} = {}) {
	return Async.Promise( (resolve, reject) => {

		//debug.log('command = ', command);
		//debug.log('args = ', args);
		//debug.log('options = ', options);

		// NOTE! If you set stdout to be captured instead of ignored (the postgres log is there),
		// pgctl start will fail to exit.

		const options = {
			env: merge(process.env, env || {}),
			detached: true,
			stdio: ["ignore", "ignore", "pipe"]
		};

		let stderr = '';

		// Run the process

		//debug.log('Executing command ', command, args);

		let proc = child_process.spawn(command, args, options);

		// Handle exit
		proc.on('close', retval => {
			//debug.log('Command ', command, args, ' closed with ', retval);
			if (retval === 0) {
				resolve(retval);
			} else {
				reject({retval, stderr});
			}
		});

		// Handle error
		proc.on('error', err => {
			reject(err);
		});

		//proc.stdout.setEncoding('utf8');
		//proc.stdout.on('data', data => {
		//	process.stderr.write(data);
		//});

		proc.stderr.setEncoding('utf8');
		proc.stderr.on('data', data => {
			stderr += data;
		});

	});
}
debug.log('pg_ctl detected as ', PG_CTL); Return promise of a spawned command

@param command {string}
@param args {array.<string>}
@param options {object}
@returns {*}