Skip to content

Callback is triggered even if not finishedΒ #127

@hgouveia

Description

@hgouveia

I'm copying some binaries file to another folder, then executing a binary in the callback
but i'm getting as a result Error: spawn EBUSY

internal/child_process.js:328
    throw errnoException(err, 'spawn');
    ^

Error: spawn EBUSY
    at exports._errnoException (util.js:1020:11)
    at ChildProcess.spawn (internal/child_process.js:328:11)
    at exports.spawn (child_process.js:370:9)

The Script:

const spawn = require("child_process").spawn;
const execPath = path.resolve( __dirname, "/dest" );
const binPath = path.resolve( __dirname, "/.bin" );

rimraf(execPath, function (err) {

    if (err) {
        throw err;
    }

    mkdirp(execPath, {}, function (err) {
        if (err) {
            throw err;
        }

        ncp(binPath , execPath, { clobber: false }, function (err) {
            if (err) {
                throw err;
            }

            let args = ["--arg1"];
            let cmd = path.resolve(execPath , "sometool.exe");
            spawn(cmd, args);
        });
    });
});

if i add a setTimeout where the binary is called, it works

const spawn = require("child_process").spawn;
const execPath = path.resolve( __dirname, "/dest" );
const binPath = path.resolve( __dirname, "/.bin" );

rimraf(execPath, function (err) {

    if (err) {
        throw err;
    }

    mkdirp(execPath, {}, function (err) {
        if (err) {
            throw err;
        }

        ncp(binPath , execPath, { clobber: false }, function (err) {
            if (err) {
                throw err;
            }

            let args = ["--arg1"];
            let cmd = path.resolve(execPath , "sometool.exe");
            

            //NOW IT WORKS
            setTimeout( ()=> spawn(cmd, args), 1000); 

        });
    });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions