src/exec.js
function sshExecSingleCommand(cnxParams, cmd, fnOutput){

  var result = {
    "command" : cmd,
    "success" : true,
    "error"   : null,
    "value"   : null
  };
  return Q.promise(function(resolve, reject) {
		var sshClient = new SSHClient();

    sshClient
		.on('ready', function() { // sshClient Ready
      var stdout = "";
      var stderr = "";

      sshClient.exec(cmd, function(err, stream) {
        if (err) {throw err;}

        stream.on('close', function(code, signal) {
          sshClient.end();
          if( code !== 0 ){
            result.success = false;
            result.error = {"stderr" : stderr, "code" : code};
            reject(result);

          } else if (fnOutput && typeof fnOutput === 'function') {
              result.value = fnOutput(stdout);
              resolve(result);
          } else {
              result.value = stdout;
              resolve(result);
          }
        }).on('data', function(data) {
          stdout += data;
        }).stderr.on('data', function(data) {
          stderr += data;
        });
      });
    })
    .on('error',function(error){ // sshClient Error
      result.success = false;
      result.error = error;
      reject(result);
    })
    .connect(cnxParams); // sshClient Connect
  });
}
function sshExecSingleCommand(cnxParams, cmd, fnOutput){

  var result = {
    "command" : cmd,
    "success" : true,
    "error"   : null,
    "value"   : null
  };
  return Q.promise(function(resolve, reject) {
		var sshClient = new SSHClient();

    sshClient
		.on('ready', function() { // sshClient Ready
      var stdout = "";
      var stderr = "";

      sshClient.exec(cmd, function(err, stream) {
        if (err) {throw err;}

        stream.on('close', function(code, signal) {
          sshClient.end();
          if( code !== 0 ){
            result.success = false;
            result.error = {"stderr" : stderr, "code" : code};
            reject(result);

          } else if (fnOutput && typeof fnOutput === 'function') {
              result.value = fnOutput(stdout);
              resolve(result);
          } else {
              result.value = stdout;
              resolve(result);
          }
        }).on('data', function(data) {
          stdout += data;
        }).stderr.on('data', function(data) {
          stderr += data;
        });
      });
    })
    .on('error',function(error){ // sshClient Error
      result.success = false;
      result.error = error;
      reject(result);
    })
    .connect(cnxParams); // sshClient Connect
  });
}
Run a single SSH command and returns the result.
When fullfilled the promise result is an object with the following properties :

- command : (string) SSH command that was executed
- success : (boolean) command execution status
- error   : (null|object) when "success" is True this property is NULL, otherwise
it contains an object describing the error
- value   : (string|null) when "success" is True contains the value returned by
the command, otherwise NULL

@param  {object} cnxParams SSH connection settings
@param  {string} cmd       the command to execute
@param  {function} fnOutput  optional function to process command output on success
@return {Promise}           Promisyfied result