从Coffee-script执行命令行顺序

MrC*_*uer 3 command-line coffeescript

是否可以执行命令行顺序,如'll','pwd'或Coffee脚本中的任何内容?

到目前为止,我试图找到没有运气的例子.

谢谢!

rob*_*kuz 11

如果您通过Node.js执行CoffeeScript,您将可以完全访问您的操作系统的功能.使用模块的spawn方法child_process创建一个新进程:

{spawn} = require 'child_process'
ls = spawn 'ls', ['array', 'of', 'options']
# receive all output and process
ls.stdout.on 'data', (data) -> console.log data.toString().trim()
# receive error messages and process
ls.stderr.on 'data', (data) -> console.log data.toString().trim()
Run Code Online (Sandbox Code Playgroud)