25 Nov 2013, 16:04
Richsmall2_pragsmall

Richard Lee (2 posts)

watcher-spawn.js doesn’t work for me.

I see:

D:\Projects\node-projects\file-system>node --harmony watcher-spawn.js target.txt
Now watching target.txt for changes...

…touch file here…

events.js:72
    throw er; // Unhandled 'error' event
          ^ Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)`

Using Windows 7, running “copy /b target.txt +,,” to touch the target file. node v0.10.22. Code is per the example in the book.

Any ideas? Thanks Rich

25 Nov 2013, 17:45
Avatar_pragsmall

Jim R. Wilson (68 posts)

Interesting! I wonder if this has to do with the way that the copy command works.

What happens if you use echo to append to the file instead?

echo.>> target.txt
26 Nov 2013, 10:18
Richsmall2_pragsmall

Richard Lee (2 posts)

Hi Jim, thanks for responding, (and thanks for the book btw)

I get the same error using echo, and if I make an edit to target.txt. The earlier examples work fine, and I double-checked using your own code.

I replaced the line with the pipe call with

console.log('made it here');

and when run the text is output before the error is thrown. I guess I’ll come back to this later wehn I have time to dig into the node docs and find out how to debug.

Cheers Rich

26 Nov 2013, 16:56
Avatar_pragsmall

Jim R. Wilson (68 posts)

Oh I see, I think I understand now. It’s probably the call to ls. Windows doesn’t have a program called ls and so it triggers the ENOENT error, which Node is bubbling up to you.

If you ran the watcher through a shell like Cygwin it might have access to ls. Alternatively, if you changed ls to dir with appropriate arguments, that might work too (dir isn’t going to recognize -h for example, since Windows command line arguments are prefixed with slashes, not dashes).

16 Sep 2014, 13:14
Img_0625_pragsmall

Nikhil Patil (1 post)

“use strict”;

const fs = require(‘fs’); const spawn = require(‘child_process’).spawn; const filename = process.argv[2];

if (!filename) { throw Error(“A file to watch must be specified!”); }

fs.watch(filename, function() {

let ls = spawn(‘ls’, [‘-lh’, filename]); ls.stdout.pipe(process.stdout);

});

console.log(“Now watching “ + filename + “ for changes…”);

output is

fs.js:1056 throw errnoException(process._errno, ‘watch’); ^ Error: watch ENOENT at errnoException (fs.js:1024:11) at FSWatcher.start (fs.js:1056:11) at Object.fs.watch (fs.js:1081:11) at Object. (/Users/nikhil/Documents/node/watcher_spawn.js:12:4) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16)

I am using Mac

  You must be logged in to comment