Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!