There is no way to synchronously return a value captured by an asynchronous 
function.

Only thing you can do is to change a signature of your function to `function 
(ProviderCommand, callback)` and call `callback(...)` at the end of the 
execution chain.

(not mentioning coroutines and promises which are fancy wrappers around the 
same idea)


28.12.2013, 20:09, "[email protected]" <[email protected]>:
> I have a 'require('child_process').exec' call that gives an anonymous 
> function to capture its output.  What I need to do is return this output to 
> the calling function.
>
> Visually Explained:
>
> function ->
>      function that Executes Child ->
>           Anonymous Function ->
>                 Return output to calling fn
>
> Code:
>
>                 launch: function (ProviderCommand) {
>                         var self = this;
>
>                         this.D("Exec: " + ProviderCommand, "Launch");
>
>                         require('child_process').exec(ProviderCommand, {
>                                 cwd: "providers"
>                         },
>                         function (error, stdout, stderr) {
>                                 self.D("Out: " + stdout, "Launch");
>                                 self.D("ERR: " + stderr, "Launch");
>                                 if (error !== null) {
>                                         self.D("Exec Error: " + error, 
> "Launch");
>                                 }
>                         });
>                 },
>
> Just ignore the calls to this.D(...) and self.D(...) they are just debugging 
> calls that write console output to my terminal...
>
> I'm at a loss as how to accomplish this, any help would be appreciated.
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to