javascript (spidermonkey) how does one run a linux command from js shell?

后端 未结 5 546
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-20 04:17

I\'m stumped and feeling stupid. I\'ve tried every search combination I can think of to figure this out. It seems simple, but being new to javascript I\'m not seeing anythin

5条回答
  •  温柔的废话
    2021-01-20 04:46

    You can do it 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 outputs a directory listing.

提交回复
热议问题