Skip to content
2012 edited this page Jul 20, 2020 · 2 revisions

模拟终端处理命令行的功能,便于 js 统一编码,而不再需要写 shell 脚本来执行命令

预习概念

  • shell vs process

exec(command[, options][, callback])

  • 会创建 shell 去运行命令
  • 会缓存命令输出的结果数据
  • 不适合处理大文件,因为内存有限
  • 不允许与主进程进行交互

execFile(file[, args][, options][, callback])

  • 与 child_process.exec() 类似,除了不衍生 shell。 可执行的 file 会被直接衍生为一个新进程,这使得它比 child_process.exec() 更高效。

fork(modulePath[, args][, options])

  • spawn 一个新的 node 进程
  • 父进程和子进程可以交互通信
  • 不会自动退出进程,使用process.exit()手动退出

spawn(command[, args][, options])

  • 不会创建 shell 去运行命令,会 spawn 一个进程去运行命令,因此比 exec 轻量
  • 使用 stream
  • 适合处理大文件
  • 完成时自动退出进程

每个方法都返回 ChildProcess 实例。 这些对象都实现了 EventEmitter 接口,允许父进程注册监听器函数,在子进程生命周期期间,当特定的事件发生时会调用这些函数。

child_process.exec() 和 child_process.execFile() 可以额外指定 callback 函数,当子进程结束时会被调用。

ps

  1. windows 环境中,不能创建 shell 的函数都不能执行,如 execFile 不能在 windows 环境中使用
  2. 不要传入不安全的命令到 shell 进程中

JS

  1. 作用域
  2. 闭包
  3. 原型(链)
  4. 模块
  5. 位操作符
  6. 事件循环
  7. eval

CSS

  1. float
  2. BFC
  3. position
  4. flex
  5. grid

DOM

  1. DOM
  2. how browser works

Node.js

  1. Stream
  2. Timers
  3. Child Processes
  4. HTTP
  5. File System

react

  1. 生命周期
  2. setState
  3. hook

git

  1. git 基础命令
  2. git rebase 理解
  3. git bisect
  4. git commit
  5. git hook

设计模式

  1. 策略模式
  2. ...

TCP/IP 协议

  1. HTTP/1.x
  2. HTTP/2
  3. SSL/TLS
  4. TCP
  5. DNS
  6. HTTP Cache
  7. CORS
  8. http status code

linux(shell)知识点

  1. bashrc vs profile
  2. vim
  3. shell基本语法
  4. shell 知识误区
  5. shell命令
  6. 鸟哥的Linux私房菜:基础学习篇
  7. sudo vs su
Clone this wiki locally