ncp icon indicating copy to clipboard operation
ncp copied to clipboard

Callback is triggered even if not finished

Open hgouveia opened this issue 7 years ago • 2 comments

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); 

        });
    });
});

hgouveia avatar Feb 07 '18 15:02 hgouveia

I think I encountered the same issue: calling "ncp", then git add ., and the copied file isn't present.

julienw avatar Feb 17 '18 13:02 julienw

Yup. I'm running into the same issue as @julienw. I'm running git add . after the callback fires. This doesn't work as expected because the files aren't copied even though the callback ran without errors.

andrewjmead avatar Dec 17 '19 19:12 andrewjmead