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

220
Views
Primero quiero conectarme a aws y presionar un comando python desde Nodejs a través de Api. ¿No estás seguro de cómo hacerlo?

Quiero ejecutar el comando 'python3 sample.py --path.data=/root/tej4' desde nodejs. El siguiente es mi código:

 const runningPython = async(req,res,next) => { ssh.connect({ host: '******', port: 22, username: 'ubuntu', privateKey: '*******' }).then(function () { exec('python3 sample.py --path.data=/root/tej4', (err, stdout, stderr) => { if (err) { console.log(err) } // the *entire* stdout and stderr (buffered) console.log(`stdout: ${stdout}`); console.log(`stderr: ${stderr}`); }); }) }

Pero lo que recibo como respuesta es que intenta ejecutarse localmente en lugar de en aws cli. ¿No estás seguro de cómo lograr esto?

 Error: Command failed: python3 sample.py --path.data=/root/tej4 Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. at ChildProcess.exithandler (node:child_process:397:12) at ChildProcess.emit (node:events:390:28) at maybeClose (node:internal/child_process:1064:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) { killed: false, code: 9009, signal: null, cmd: 'python3 sample.py --path.data=/root/tej4' } stdout: stderr: Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe crear una instancia de tipo node_ssh y usar esa instancia para llamar a los métodos de connect y executeCommand

 const node_ssh = require('node-ssh'); const ssh = new node_ssh(); ssh .connect({ host: '******', port: 22, username: 'ubuntu', privateKey: '*******' }) .then(() => { ssh.execCommand('python3 sample.py --path.data=/root/tej4', { cwd:'/your-python-script-path-here' }) .then((result) => { console.log('STDOUT: ' + result.stdout) console.log('STDERR: ' + result.stderr) });
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar ssh lib, pero para sudo su y ejecutar varios comandos cambie a ssh2shell, el código para eso se menciona a continuación:

 const runningPython = async (req, res, next) => { var host = { server: { host: ***** , username: ***** , privateKey: fs.readFileSync('ppk file path'), }, commands: ["sudo su -", "python3 sample.py --path.data=root/tej4"], onCommandComplete: function (command, response, sshObj) { if (sshObj.debug) { this.emit("msg", this.sshObj.server.host + ": host.onCommandComplete event, command: " + command); } if (command === "sudo su -" && response.indexOf("/root") != -1) { sshObj.commands.unshift("msg:The command and response check worked. Added another cd command."); sshObj.commands.unshift("cd .ssh"); } else if (command === "python3 sample.py --path.data=root/tej4") { this.emit("msg", response); } }, onEnd: function (sessionText, sshObj) { if (sshObj.debug) { this.emit("msg", this.sshObj.server.host + ": host.onEnd event"); } } }; let SSH = new SSH2Shell(host), //Use a callback function to process the full session text callback = function (sessionText) { console.log(sessionText) } //Start the process SSH.connect(callback); }
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!