Exec refactoring

Remember to merge https://github.com/appium/appium/pull/4103 after this.
Gotcha.  Agreed.

On Tue, Nov 25, 2014 at 2:08 PM, Jonathan Lipps <notifications@github.com>
wrote:

> In lib/helpers.js:
>
> > +var wrapForExec = function (s) {
> > +  // not a string
> > +  if (typeof s !== 'string') return s;
> > +  // already wrapped
> > +  if (s.match(/^['"].*['"]$/)) return s;
> > +  // wrap if necessary;
> > +  if (s.match(/[\s"]/)) {
> > +    // escape quote
> > +    s = s.replace(/"/g, '\\"');
> > +    return '"' + s + '"';
> > +  }
> > +  return s;
> > +};
> > +exports.wrapForExec = wrapForExec;
> > +
> > +exports.prettyExec = function (/*cmd, args, opts, cb*/) {
>
>  Anyway, it'd be nice to do everything via spawn or exec if possible
> since they have different behavior.
>
> I'm not sure we want just one method to use. We need two methods with
> different APIs since we have two use cases:
>
>    1. Executing a command and doing something with the result
>    2. Running a long-lived subprocess while we do other things,
>    monitoring stdout and exit codes etc...
>
> What we don't care about is how it works under the hood. In my mind we
> were going to create a library which exported two methods, spawn and exec,
> which we just use instead of Node's child_process methods. These would work
> functionally the same as Node's versions, except:
>
>    1. They do the right thing with spaces in paths in all cases, no
>    matter what we pass in
>    2. exec actually runs spawn under the hood to get around the buffer
>    limitation
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/appium/appium-adb/pull/63/files#r20886431>.
>