Javascript (spidermonkey) how to run linux command from js shell?

I'm at a dead end and feeling stupid. I have tried every search combination that I think of in order to figure this out. It seems simple, but being new to javascript, I don't see anything useful in finding examples or demos. I want to use a script like I would have a python or perl script to run a simple linux command. The translator is up and running, so I'm just looking for js server resources for more information about js. I found many examples when I want to do these things in a browser, but I do not want to use a browser. I could not find such a request on the site (although I am sure that I am not setting the correct path). If this is really an extra post, you can close it and direct it in the right direction.

+3
source share
5 answers

You do not have access to the system outside the browser. Whether it is Windows or Linux, your "js shell" is placed in a browser window. Access to the file system or applications outside of the browser is not available. JS is a scripting language that is interpreted by the browser.

You have access to the world outside of the browser, but only in IE using ActiveX, but then it is outside the sandbox and it is not pure javascript. If you are looking for forums, you will not find documentation that talks about file access in javascript without ActiveX. ActiveX is not available on Linux or Firefox.

You might want to check out Wikipedia to learn more about javascript, the DOM, and the sandbox. http://en.wikipedia.org/wiki/JavaScript

+1

"system()" , (, SpiderMonkey.)

, JSNative- myjs_system(), JavaScript.

+1

, . Jscript jsc.exe, .NET Framework Windows:

> var myFileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
> 
> var pathToFileDir = ".";
> var myFolder = myFileSystemObj.GetFolder(pathToFileDir);
> 
> var myEnum = new
> Enumerator(myFolder.Files);
> 
> for
> (;!myEnum.atEnd();myEnum.moveNext()) {
>   print(myEnum.item()) }

, ol. , , , Linux? Spidermonkey JS_HAS_FILE_OBJECT=1, , , , , . -, javascript, ( " N", N = python, perl, java ..).

+1

For linux, I found that EJScript supports files that work out of the box. This allows me to do what I want to do anyway. I'm still trying to get a spidermonkey compiled with the File_Object flag because I am stubborn, but so far I have no problem with the EJScript recommendation for programmers who want to try server-side JavaScript code.

+1
source

You can do this with node.js' exec.

# install node.js (debian/ubuntu)
sudo apt-get install nodejs

# run node.js CLI
node

From an example found here :

var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("ls -la", puts);

This lists the directories.

+1
source

All Articles