3

是否可以从 Coffee 脚本执行命令行命令,例如“ll”、“pwd”或任何其他命令?

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

谢谢!

4

1 回答 1

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()
于 2012-09-17T14:18:28.363 回答