+1  A: 

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
Where's the download for Rhino shell? My google-fu is failing me.
Herms
Nm, finally found it: http://www.mozilla.org/rhino/download.html
Herms
@Matthew Crumley Thanks dude, if nothing helps, I think I'll do it with Rhino (actually I don't care it so much, just impressed how to do it)@Herms Sources are here http://www.mozilla.org/rhino/download.html
Mushex Antaranian