Javascript interpreter for Linux

21,139

Solution 1

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

Solution 2

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.

Solution 3

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

So you would have

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

or perhaps

install('myapp.rpm');
install('myapp2.rpm');
Share:
21,139

Related videos on Youtube

Madalina
Author by

Madalina

Updated on July 09, 2022

Comments

  • Madalina
    Madalina almost 2 years

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

    • oneat
      oneat almost 14 years
      Why don't you write it in bash?
    • Madalina
      Madalina almost 14 years
      Yes, that was the first option, but someone suggested me to use javascript, so thats why I'm wondering if it is possible or not. :)
  • Madalina
    Madalina almost 14 years
    I don't need a browser emulator. All I want to do is run a javascript file (using an interpretor) that runs some linux commands. Is it possible to do this? And also I would prefer not to depend on Java, because my javascript file should make some installations on my linux machine. I don't know if my questions is clear, but I was suggested to use javascript for doing this, and I don't realy know how.
  • Madalina
    Madalina almost 14 years
    Yes, I need to run something like system('rpm -i myapp.rpm'), but directly from Javascript, because I can't depend on other languages, like C++ or Java.
  • Aaron Digulla
    Aaron Digulla almost 14 years
    Since JavaScript is an interpreted language, you need an interpreter. For the interpreter to run, you need some other language.
  • T.J. Crowder
    T.J. Crowder almost 12 years
    "For the interpreter to run, you need some other language." No, you don't need another language. You just need a JavaScript engine. V8 (Google's JavaScript engine), for instance, is a compiled executable. You don't need another language runtime (Python, the JVM, perl, whatever) to run it.
  • Aaron Digulla
    Aaron Digulla almost 12 years
    Which is what I meant: You need V8.