是否可以从 Coffee 脚本执行命令行命令,例如“ll”、“pwd”或任何其他命令?
到目前为止,我试图找到没有运气的例子。
谢谢!
如果您通过 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()