Veracity Q&A home login about faq

I'm trying to run vscript with -e to execute a script snippet, and then exit. But I would like to pass arguments to the the snippet. I know this is a weird request because I can just embed the arguments into the snippet, but I'm trying to keep the snippet text constant and small, as the argument values can be a bit longer.

If I do this:

vscript -e "print(arguments[0])" hello

I get:

undefined
can't open hello: No such file or directory

If I do this:

vscript -e "print(arguments[0])" hello
I get:
hello
can't open a: No such file or directory

Which is close, but I don't want that error (it is obviously trying to take the first argument as a script filename to execute, but I don't have a file to execute).

If I make the first argument "-" it runs the snippet and then drops to the interactive prompt. Which is also undesirable. Adding "quit();" to the end of my snippet doesn't change anything.

asked Feb 06 at 10:26

jslutter's gravatar image

jslutter
2165919


The only way to get parameters into the arguments array is when they follow a script file. You can either supply a /dev/null-type device, or keep an empty file around for this purpose. The latter seems to be more consistent across platforms.

So if your script first creates an empty, or full-of-blanks dummy.js file, you can say:

vscript -e "print(arguments[0])" dummy.js hello

and you'll see

hello

as you hope.

link

answered Feb 06 at 10:52

Paul%20Roub's gravatar image

Paul Roub ♦♦
1.6k81141

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×5

Asked: Feb 06 at 10:26

Seen: 272 times

Last updated: Feb 06 at 10:52

powered by OSQA