M
M
MarEeeeeee2020-10-01 17:46:33
JavaScript
MarEeeeeee, 2020-10-01 17:46:33

How to get data from a function?

I have the following function, I need to get the data field from it. But for some reason it does not return values ​​using return. How can this problem be solved?

function get_win_drives(success_cb,error_cb){
    var stdout = '';
    var spawn = require('child_process').spawn,
            list  = spawn('cmd');

    list.stdout.on('data', function (data) {
        stdout += data;
    });

    list.stderr.on('data', function (data) {
        console.log('stderr: ' + data);
    });

    list.on('exit', function (code) {
        if (code == 0) {
            // console.log(stdout);
            var data = stdout.split('\r\n');
            data = data.splice(4,data.length - 7);
            data = data.map(Function.prototype.call, String.prototype.trim);
            console.log(data);
            // success_cb(data);
        } else {
            console.log('child process exited with code ' + code);
            error_cb();
        }
    });
    list.stdin.write('wmic logicaldisk get caption\n');
    list.stdin.end();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-10-01
@yarkov

Uncomment the line and work with data// success_cb(data); inside the success_cb function .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question