Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript interpreter for Linux

Is there a way to run linux commands from javascript that uses a standalone interpreter (something similar with SpiderMonkey, JavaScript shell)?

like image 284
Madalina Avatar asked Aug 06 '10 08:08

Madalina


People also ask

Can JavaScript be used in Linux?

We're not sure what makes JavaScript less "real" to some, but thanks to today's web browsers, JavaScript has become a very powerful language. Powerful enough to run Linux in your web browser. French developer Fabrice Bellard has built a JavaScript-based x86 PC emulator capable of running Linux inside a web browser.

Is there a JavaScript interpreter?

In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. More modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.

Is it possible to run JavaScript on Linux?

Since JavaScript is an interpreted language, you need an interpreter. For the interpreter to run, you need some other language. Linux doesn't come with one built-in (like it does for shell scripts or similar). If you need scripting, use Bash or (for more complex scripts) Python.

What is the best Linux text editor for JavaScript?

The extension to Vim, considered by many as the best Unix text editor ever, Neovim comes with enough powerful features to be your next Javascript Editor for Linux.

What is a sandbox PHP interpreter?

A JavaScript interpreter written in PHP 5, that allows to run untrusted scripts in a sandbox on your server. It aims to implement most of Ecma-262 3d edition.

What is jslibs in Linux?

jslibs is a standalone JavaScript interpreter that runs on Linux32/64 and Windows. You can easily run linux commands through the libraries provided by jslibs. It's possible to define JS functions that will call your C/C++ functions that could use system() call, executing some linux commands.


3 Answers

You could use NodeJS. It has a child_process module that can run arbitrary commands. E.G. child_process.spawn()

When your script is finished you run it like this:

node myscript.js
like image 110
Alejandro Moreno Avatar answered Oct 18 '22 03:10

Alejandro Moreno


jslibs is a standalone JavaScript interpreter that runs on Linux32/64 and Windows.
You can easily run linux commands through the libraries provided by jslibs.

like image 34
Franck Freiburger Avatar answered Oct 18 '22 01:10

Franck Freiburger


It's possible to define JS functions that will call your C/C++ functions that could use system() call, executing some linux commands.

  • Spider Monkey's way: https://developer.mozilla.org/en/JavaScript_C_Engine_Embedder's_Guide#Native_functions

  • Google V8 is also an option: http://code.google.com/apis/v8/embed.html#accesssors

So you would have

system('rpm -i myapp.rpm');
system('rpm -i myapp2.rpm');

or perhaps

install('myapp.rpm');
install('myapp2.rpm');
like image 2
Dmitry Yudakov Avatar answered Oct 18 '22 03:10

Dmitry Yudakov