Ubuntu 12.04 Node v0.6.14 CoffeeScript 1.3.1
fs.watchFile coffee_eval, (e) ->
console.log e
result = spawn 'coffee', ['-bc', coffee_eval]
msg = ''
result.stderr.on 'data', (str) ->
msg+= str
result.stderr.on 'end', ->
console.log 'msg: ', msg
print "!! #{coffee_eval}\n"
Run Code Online (Sandbox Code Playgroud)
要点上的完整代码:https : //gist.github.com/2621576
每次我保存一个被监视的文件时,主函数被称为 twitce 而不是一次。
我的编辑器是 Sumlime Text 2。
输出词可以看到:

问题仍然存在,这是我找到的方法。
var actionDone = {}
fs.watch('.', function(x,filename) {
var path = './'+filename;
var stats = fs.statSync(path);
let seconds = +stats.mtime;
if(actionDone[filename] == seconds) return;
actionDone[filename] = seconds
//write your code here
});
Run Code Online (Sandbox Code Playgroud)
我们在继续之前检查上次修改时间是否不同。
| 归档时间: |
|
| 查看次数: |
4502 次 |
| 最近记录: |