Skip to content

Passed process arguments to executable script#36

Merged
arturadib merged 2 commits intoshelljs:masterfrom
Zanisimo:process-arguments
Nov 6, 2012
Merged

Passed process arguments to executable script#36
arturadib merged 2 commits intoshelljs:masterfrom
Zanisimo:process-arguments

Conversation

@Zanisimo
Copy link
Copy Markdown

This will allow to pass arguments to executable script from process.argv.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused - how is it that this "fixes" the arguments? It seems to simply wrap each word in quotes, i.e.

shjs test word1 word2 word3

gets mapped into

"word1" "word2" "word3"

@Zanisimo
Copy link
Copy Markdown
Author

Hi. That will fix for this kind of example:

If you will use something like shjs myscript.js -a "{ a : 1, b :1}" in the process.argv you will get process.argv.a to be equal to that JSON object ({ a : 1, b : 1}) so you can loop the process.argv and put all values that don't start with '-' in quotes to be passed as string to executable script.

For example if you would pass the same object to the script without quotes the result in process.argv would be:

[ '{', 'a', ':', '1,', 'b', ':', '1}' ]

@Zanisimo
Copy link
Copy Markdown
Author

Could you please merge this. I am using it in my project and it works great.

@arturadib
Copy link
Copy Markdown
Collaborator

sorry for the delay -- now I get it, merging, thanks!

arturadib added a commit that referenced this pull request Nov 6, 2012
Passed process arguments to executable script
@arturadib arturadib merged commit f58dcd1 into shelljs:master Nov 6, 2012
@Zanisimo
Copy link
Copy Markdown
Author

Zanisimo commented Nov 7, 2012

No worries. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants