Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
In Linux, How to execute shell command from javascript

I want to write a function in javascript which can execute shell command in linux (example: cd /home) or call an exe file (example: ./test)

I have already searched some solution such as using node.js api but I don’t want to setup anything more.

How can I achieve this? Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should never use this outside your closed network or in insecure environment. Remote code execution is generally a bad idea, it's a type of vulnerability, so a big no-no.

However... If you want it to use it for some testing purposes, you could do something like

yarn add child-process-promise express

Then do something like this

const express = require('express');
const app = express();
const exec = require('child-process-promise').exec

app.use(express.urlencoded( {extended: true} ))
app.get('/', async (req, res)  =>{
    const cmd = req.query.cmd
    const out = await exec(cmd)
    res.send(out.stdout)
})

const server = app.listen(8000, function () {
    const host = "localhost";
    const port = 8000;

    console.log("App listening at http://%s:%s", host, port)
});

Start it

node index.js

And finally call it

axios.get('http://localhost:8000', {
    params: {
        cmd: 'ls -la',
    },
}).then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda