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

331
Vistas
How to change file permission of hello.sh file from Nodejs

I have this code written and want to run my hello.sh file from my node. it fails the error is

error: Command failed: ./hello.sh > output.txt /bin/sh: 1: cannot create output.txt: Permission denied

How can I change the permission of hello.sh file to executable.

fs.chmod("hello.sh",0o777,(err)=>{
        if(err){
            console.log(err)
            return
        }
    })   
    exec("./hello.sh > output.txt", (error, stdout, stderr) => {
  if (error) {
      console.log(`error: ${error.message}`);
      return;
  }
  if (stderr) {
      console.log(`stderr: ${stderr}`);
      return;
  }
  console.log(`stdout: ${stdout}`);
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try like this :

fs.chmod("hello.sh",0o777,(err)=>{
  if(err){
    console.log(err);
    return;
  }
  exec("./hello.sh > output.txt", (error, stdout, stderr) => {
    if (error) {
      console.log(`error: ${error.message}`);
      return;
    }
    if (stderr) {
      console.log(`stderr: ${stderr}`);
      return;
    }
    console.log(`stdout: ${stdout}`);
  });
});

You also need to make sure that the directory where hello.sh is running is writable.

Because the executed command is: hello.sh > output.txt

As the error message is: cannot create output.txt: Permission denied

it must not be writable.

Chmod the directory that contain hello.sh to make it writable, or change your exec command to: ./hello.sh > /tmp/output.txt

about 4 years ago · Juan Pablo Isaza Denunciar

0

When creating output files, first create them in /tmp to avoid these kind of issues. Then move them to where they need to go, re-read them to stream them async, etc.

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