Skip to content

Instantly share code, notes, and snippets.

@xeb
Created August 23, 2011 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeb/1164511 to your computer and use it in GitHub Desktop.
Save xeb/1164511 to your computer and use it in GitHub Desktop.
Ha! Reading a file in Node... don't forget the toString!
var
sys = require("sys")
, fs = require("fs")
, path = require("path")
, exec = require("child_process").exec
;
console.log("Staring");
var file = __dirname + "\\input.txt";
console.log("reading " + file);
fs.readFile("input.txt", function(err, data) {
if(err) {
throw err;
return;
}
if(data) {
console.log(data);
// execute the child process based on the input file
exec('cat < ' + data, function(err, stdout, stderr) {
console.error(err);
console.error(stderr);
console.log('OUTPUT==');
console.log(stdout);
});
}
});
var
sys = require("sys")
, fs = require("fs")
, path = require("path")
, exec = require("child_process").exec
;
console.log("Staring");
var file = __dirname + "\\input.txt";
var data = fs.readFile("input.txt", function(err, data){
if(err) throw err;
console.log(data.toString());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment