How to pass arguments to a script through the SpiderMonkey command-line?

早过忘川 提交于 2020-01-06 08:01:15

问题


I am using SpiderMonkey 1.8.5 on Debian. I am starting a script through the command-line using

js -f <myScript>

I'd like to pass some arguments to my script, but I don't know how to do that. It's supposedto be possible since the documentation tells you about a special object gathring all parameters provided to a script.

I tried the following:

js -f <myScript> <1stArg>

But SpiderMonkey consider both parameters as different scripts to execute and thus sends en error saying the '<1stArg>' file doesn't exist.

What is the correct way to do what I wish?


回答1:


Like this:

In script.js

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

Then from system shell:

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


来源:https://stackoverflow.com/questions/11073713/how-to-pass-arguments-to-a-script-through-the-spidermonkey-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!