const fs = require("fs");
const path = require("path");
const os = require('os');
const spawn = require('child_process').spawnSync;

function exec_tf(args) {

    const result = isWindows() ?
        exec_tf_win(args) :
        exec_tf_unix(args);

    // const out = result.stdout.toString();
    // if (out !== "") console.log(out);

    // const error = result.stderr.toString();
    // if (error !== "") console.log(error);

    return result.status;
}

function isWindows() {
    return os.platform() === 'win32';
}

function exec_tf_win(args) {
    const tfPath = path.resolve(__dirname, 'tf.cmd');
    return spawn(process.env.comspec, ["/c", tfPath, ...args]);
}

function exec_tf_unix(args) {
    const tfPath = path.resolve(__dirname, 'tf');
    return spawn(tfPath, args);
}


module.exports = exec_tf;