var _exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');

/*
 * 运行Linux命令
 * */
var runCommand = function(cmd,callback){
    _exec(cmd, function (err, stdout, stderr) {
        if(callback && typeof callback == 'function'){
            callback(err,stdout, stderr);
        }
    });
}
exports.runCommand = runCommand;

//创建多层文件夹 同步
var mkdirsSync = function(dirpath, mode) {
    if (!fs.existsSync(dirpath)) {
        var pathtmp;
        dirpath.split(path.sep).forEach(function(dirname) {
            if (pathtmp) {
                pathtmp = path.join(pathtmp, dirname);
            }
            else {
                pathtmp = dirname;
            }
            if (!fs.existsSync(pathtmp)) {
                if (!fs.mkdirSync(pathtmp, mode)) {
                    return false;
                }
            }
        });
    }
    return true;
}
exports.mkdirsSync = mkdirsSync;