【问题标题】:How to pass arguments to a script through the SpiderMonkey command-line?如何通过 SpiderMonkey 命令行将参数传递给脚本?
【发布时间】:2012-06-19 21:12:24
【问题描述】:

我在 Debian 上使用 SpiderMonkey 1.8.5。 我正在使用

通过命令行启动一个脚本
js -f <myScript>

我想将一些参数传递给我的脚本,但我不知道该怎么做。这应该是可能的,因为the documentation 告诉你一个特殊的对象,它收集了提供给脚本的所有参数。

我尝试了以下方法:

js -f <myScript> <1stArg>

但 SpiderMonkey 将这两个参数视为要执行的不同脚本,因此会发送错误消息,指出“”文件不存在。

按照我的意愿做事的正确方法是什么?

【问题讨论】:

  • 您参考的文档中的哪几行谈到“收集提供给脚本的所有参数”?

标签: command-line-arguments spidermonkey


【解决方案1】:

像这样:

在 script.js 中

#!/usr/bin/js
print(arguments);

然后从系统外壳:

$ chmod +x script.js
$ ./script.js

【讨论】:

    猜你喜欢
    • 2017-04-20
    • 2013-10-11
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 2013-10-22
    • 2016-12-19
    • 1970-01-01
    相关资源
    最近更新 更多