chacko
chacko

Reputation: 5164

javascript - not in the browser - but to process a file

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.

Upvotes: 0

Views: 577

Answers (3)

oberhamsi
oberhamsi

Reputation: 1361

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/

Upvotes: 0

KooiInc
KooiInc

Reputation: 122906

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.

Upvotes: 1

Richard H
Richard H

Reputation: 39055

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

Upvotes: 1

Related Questions