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

160
Views
Can't run terminal commands with exec

i'm trying to use exec function in nodejs, but it's not working.

Here is the code that i'm runing :

import { exec } from "child_process";

exec("ssh ubuntu@myserverip", (error, stdout, stderr) => {
    if (error) {
        console.error(`error: ${error.message}`);
    }

    if (stderr) {
        console.error(`stderr: ${stderr}`);
    }

    else {
        console.log(`stdout:\n${stdout}`);
    }
});

And that it what it returns :

terminal

While this is the output if I directly write on terminal :

terminal

Any idea about how can I fix it ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use spawn, exec is used to execute commands whose result is going to be delivered to me immediately, or in a very short time, it has to be fast and where the output or the result that is going to be delivered to me is not very large, because exec creates a Buffer (a memory space) where it will start storing all the output of the command, and besides that it has a timeout, and if the command does not finish in that time it kills the process.

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!