1.0.40 • Published 4 months ago

app-lib-exec v1.0.40

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

一、背景介绍

  • 直接通过js调动系统的脚本bat,shell等
  • 进程自动化处理一些事情

二、功能描述

  1. 支持能在终端执行的所有命令
  2. 支持bat、shell等文件的直接执行

三、注意事项

  • 打印乱码的时候 需要设置调用参数添加options.stdio即可
    [{stdio: 'pipe'}]
  • option 支持的参数

      * stidio 支持的 [pipe,overlapped,ignore,inherit]
        分别对应 subprocess.stdin, subprocess.stdout, and subprocess.stderr的输出
        
        'pipe': equivalent to ['pipe', 'pipe', 'pipe'] (the default)
        'overlapped': equivalent to ['overlapped', 'overlapped', 'overlapped']
        'ignore': equivalent to ['ignore', 'ignore', 'ignore']
        'inherit': equivalent to ['inherit', 'inherit', 'inherit'] or [0, 1, 2] // Child will use parent's stdios.
         自定义
         stdio: ['pipe', 'pipe', process.stderr]  // Spawn child sharing only stderr.
    
      * cwd 指定路径

四、使用案列

  • 引用
    const { exec } = require('app-lib-exec');
  • 同步
    exec('npm', ['list', '-g', '-depth', '0']); 
  • 执行文件
    ```
    exec('tree.bat');
    ```

五、todo列表

  • 日志外层输出

六、API

exec(commondOrFile, args, options, isAsync) ⇒ null


数据类型判断

Kind: global function
Returns: null - 无返回

Examples

option下支持的参数

  • stidio 支持的 pipe,overlapped,ignore,inherit
       inherit  // Child will use parent's stdios.
       stdio: ['pipe', 'pipe', process.stderr]  // Spawn child sharing only stderr.
ParamTypeDefaultDescription
commondOrFilestring可执行的文件路径或者文件
argsarray所有命令行参数
optionsobject执行参数配置
isAsyncbooleantrue是否同步

七、发布日志