0

I have written some javascript which reads data in a textarea (inside a browser) and outputs the result in a string (as innerHTML) in a div.

It's brilliant and it does its job.

I would like to port it out of the browser.

I would like to reuse the same javascript (which effectively is just a function that given a string returns another string) out of the browser.

Ideally I would like to run it a commandline tool and say read file c:\input.txt and writes the response on c:\output.txt

Can somebody suggest how best I can achieve this ?

I looked around and came across to commonjs.org (which is very interesting) and node.js (which is interesting too) as well as other obscure projects.

Yet, I still don't know how to do this. If somebody has done something similar I would like to hear.

Many Thanks,

p.s. I tagged this question 'server-side javascript' mainly to say that it's not a browser question.

chacko
  • 5,004
  • 9
  • 31
  • 39

3 Answers3

1

Rhino from Mozilla is javascript interpreter written in java which might do what you need.

Richard H
  • 38,037
  • 37
  • 111
  • 138
  • Agree, Rhino is the best way to do this. You can crank out a commandline utility in no time. Also useful thread: http://stackoverflow.com/questions/585234/how-to-read-and-write-into-file-using-javascript – Shakakai Feb 16 '11 at 11:36
  • Rhino is good. Okay !!! But before I give the 'ok' I would like to hear from others. Ideally I would like to run some proper javascript engine (such as V8) rather than a javascript engine written in java. – chacko Feb 16 '11 at 11:56
  • v8 is written in C and rhino in java, i don't see how one is more 'proper' then the other? – oberhamsi Feb 18 '11 at 09:05
1

If your're on a windows system, you could the native c-/wscript interpreter using the FileSystemObject to read and write files. Otherwise jsdb may be an option, where you can use the Stream-object.

KooiInc
  • 119,216
  • 31
  • 141
  • 177
0

http://RingoJs.org

It's a thin wrapper on top of Rhino. Makes dealing with files, modules, etc a lot easier, see for example: http://ringojs.org/api/master/fs/

oberhamsi
  • 1,303
  • 8
  • 18