javascript - 不在浏览器中 - 而是处理文件
我写了一些 javascript 来读取文本区域中的数据(在浏览器内) 并将结果输出到 div 中的字符串(作为innerHTML)中。
它非常出色并且发挥了它的作用。
我想将其从浏览器中移植出来。
我想在浏览器中重用相同的 JavaScript(它实际上只是一个给定字符串返回另一个字符串的函数)。
理想情况下,我想运行一个命令行工具,并说读取文件 c:\input.txt 并将响应写入 c:\output.txt
有人可以建议我如何最好地实现这一目标吗?
我环顾四周,发现了 commonjs.org(非常有趣)和 node.js (这也很有趣)以及其他不起眼的项目。
然而,我仍然不知道该怎么做。如果有人做过类似的事情,我想听听。
非常感谢,
ps 我将这个问题标记为“服务器端javascript”主要是为了说这不是浏览器问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Mozilla 的 Rhino 是用 java 编写的 JavaScript 解释器,它可以满足您的需要。
Rhino from Mozilla is javascript interpreter written in java which might do what you need.
如果您使用的是 Windows 系统,则可以使用 FileSystemObject 来读取和写入文件。否则 jsdb 可能是一个选项,您可以在其中使用
Stream
对象。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.http://RingoJs.org
它是 Rhino 之上的一个薄包装。使处理文件、模块等变得更加容易,例如:http://ringojs.org/ api/master/fs/
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/