For instance, if you were to run a Python script you would type python filename.py or if you wanted to run a C program make filename then ./ filename. How do you do this with .js files?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You would need a JavaScript engine (such as Mozilla’s Rhino) in order to evaluate the script – exactly as you do for Python, though the latter ships with the standard distribution.
If you have Rhino (or alternative) installed and on your path, then running JS can indeed be as simple as
It’s worth noting though that while JavaScript is simply a language in its own right, a lot of particular scripts assume that they’ll be executing in a browser-like environment – and so try to access global variables such as
location.href, and create output by appending DOM objects rather than callingprint.If you’ve got hold of a script which was written for a web page, you may need to wrap or modify it somewhat to allow it to accept arguments from stdin and write to stdout. (I believe Rhino has a mode to emulate standard browser global vars which helps a lot, though I can’t find the docs for this now.)