Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:13:35+00:00 2026-06-12T01:13:35+00:00

The result is populated in the exec function, but it never gets back to

  • 0

The result is populated in the exec function, but it never gets back to the main thread… what am I doing wrong?

  var Fiber, exec, execSync;

  exec = require("child_process").exec;

  Fiber = require('fibers');

  execSync = function(cmd) {
    var cmdExec, final;
    cmdExec = function(cmd) {
      var fiber,
        _this = this;
      fiber = Fiber.current;
      exec(cmd, function(se, so, e) {
        var result;
        fiber.run();
        result = se + so + e;
        return result;
      });
      return Fiber["yield"]();
    };
    final = '';
    Fiber(function() {
      return cmdExec(cmd);
    }).run();
    return final;
  };

  console.log(execSync('ls ..'));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:13:36+00:00Added an answer on June 12, 2026 at 1:13 am

    there’s a few problems in that code.. Here’s some code that does what you want:

    var Fiber, exec, execSync;
    
    exec = require("child_process").exec;
    
    Fiber = require('fibers');
    
    execSync = function(cmd) {
      var fiber = Fiber.current;
      exec(cmd, function(err, so, se) { 
        if (err) fiber.throwInto(err);
        fiber.run(se + so);
      });
      return Fiber.yield();
    };
    
    Fiber(function() {
      console.log(execSync('ls ..'));
    }).run();
    

    The big problem is that you seem to be mixing up the role of run and yield. Basically yield suspends a Fiber and run will resume (or start it for the first time). What you should be doing is running any code that needs to call execSync inside a Fiber, and then execSync will grab a reference to the current fiber and then call Fiber.yield(). When the exec call returns the fiber is resumed with fiber.run().

    The other smaller issue is some confused parameters to the callback for exec. The parameters are err, stdout, stderr.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

... // result is a JSON data passed to this function from outside var
var result = (from p in productInQuery join o in orderInfoQuery on p.refNo equals
var result = from lr in _db.LeaveRequest join th in _db.TotalHourslu on lr.TotalHoursEffect equals
var result = from lr in _db.LeaveRequest join th in _db.TotalHourslu on lr.TotalHoursEffect equals
var result = db.PhotoAlbums.Select(albums => new PhotoAlbumDisplay { AlbumID = albums.AlbumID, Title = albums.Title,
I have a table that is populated from a JSON object. The result is
I have a dropdown list that is currently populated from a result set of
My tables are populated using jsp scriptlets. Displaying is not a problem but when
In my main application I have a result event and an XMLList , which
I have a sparsely populated matrix that's the result of a series of left

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.