如何编写简单的JScript输入/输出程序? [英] How can I write a simple JScript input/output program?

查看:79
本文介绍了如何编写简单的JScript输入/输出程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划明天使用JavaScript参加信息学比赛(BIO).但是,我不能依靠审查员使用具有不错的JavaScript引擎的浏览器,因此我希望改用Microsoft的JScript.

I'm planning on using JavaScript to enter an informatics competition (BIO) tomorrow. However, I can't rely on the examiner having a browser with a decent JavaScript engine, so I was hoping to use Microsoft's JScript instead.

但是,坦率地说,该文档简直就是废话.有人可以张贴一些示例代码来读取一行文本,在其上调用foo(string),并将输出回显到命令行吗?

However, the documentation is, quite frankly, crap. Can someone post some example code that reads in a line of text, calls foo(string) on it, and echos the output to the command line?

类似地,我实际上如何运行它? wscript.exe PATH_TO_JS_FILE会成功吗?

Similarly, how do I actually run it? Will wscript.exe PATH_TO_JS_FILE do the trick?

推荐答案

如果您使用的是命令行,我将使用CSCRIPT.EXE执行脚本. 即:CSCRIPT.EXE myscript.js 这是因为WSCRIPT中的WScript.Echo将创建一个对话框,而CSCRIPT中的则将一行输出到控制台.在命令窗口(CMD)中运行它.

If you're using the command-line, I'd execute the script using CSCRIPT.EXE. ie: CSCRIPT.EXE myscript.js This is because WScript.Echo from WSCRIPT will create a dialog box and from CSCRIPT outputs a line to the console. Run this in a command window (CMD).

从控制台将一行读入变量:

Reading a line from console into variable:

var x = WScript.StdIn.ReadLine();

StdIn TextStream对象.还有一个StdOut可以代替WScript.Echo() ...

Where StdIn is a TextStream object. There is also an StdOut which can be used in place of WScript.Echo()...

foo(x)的输出写入控制台:(必须在CSCRIPT下运行)

Writing the output of foo(x) to console: (must run under CSCRIPT)

WScript.Echo(foo(x));

您可以使用WScript对象来确定要在哪个引擎上运行,对此有一个问题(VBScript,但在JScript下使用相同的对象).

You can use the WScript object to determine which engine you are running under, there's a question/answer for that (VBScript, but uses the same objects under JScript) here.

这篇关于如何编写简单的JScript输入/输出程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆