zoukankan      html  css  js  c++  java
  • nodejs调用shell

    shelljs

    https://github.com/shelljs/shelljs

    实例

    var shell = require('shelljs');
    
    if (!shell.which('git')) {
      shell.echo('Sorry, this script requires git');
      shell.exit(1);
    }
    
    // Copy files to release dir
    shell.rm('-rf', 'out/Release');
    shell.cp('-R', 'stuff/', 'out/Release');
    
    // Replace macros in each .js file
    shell.cd('lib');
    shell.ls('*.js').forEach(function (file) {
      shell.sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
      shell.sed('-i', /^.*REMOVE_THIS_LINE.*$/, '', file);
      shell.sed('-i', /.*REPLACE_LINE_WITH_MACRO.*
    /, shell.cat('macro.js'), file);
    });
    shell.cd('..');
    
    // Run external tool synchronously
    if (shell.exec('git commit -am "Auto-commit"').code !== 0) {
      shell.echo('Error: Git commit failed');
      shell.exit(1);
    }
    
    var version = exec('node --version', {silent:true}).stdout;
    
    var child = exec('some_long_running_process', {async:true});
    child.stdout.on('data', function(data) {
      /* ... do something with data ... */
    });
    
    exec('some_long_running_process', function(code, stdout, stderr) {
      console.log('Exit code:', code);
      console.log('Program output:', stdout);
      console.log('Program stderr:', stderr);
    });
    
  • 相关阅读:
    Atcoder Grand Contest 003 题解
    Atcoder Grand Contest 002 题解
    Atcoder Grand Contest 001 题解
    网络流24题
    AGC005D ~K Perm Counting
    loj6089 小Y的背包计数问题
    CF932E Team Work
    组合数学相关
    SPOJ REPEATS
    [SDOI2008]Sandy的卡片
  • 原文地址:https://www.cnblogs.com/itech/p/13253443.html
Copyright © 2011-2022 走看看