The problem is that gedit is sending the document into your program's standard input, not as a command-line argument. The SpiderMonkey shell has a readline()
function that reads a line from stdin, but it doesn't have a way of knowing when you reach EOF.
If you compile SpiderMonkey with File
support, you could probably do it, but I've never tried that.
If you use the Rhino shell, you can use Java classes directly like this:
function readStdin() {
var stdin = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.System["in"]));
var lines = [];
var line;
while ((line = stdin.readLine()) !== null) {
lines.push(line);
}
return lines.join("\n");
}
var body = readStdin();
Matthew Crumley
2009-09-15 19:15:35