Created
November 18, 2020 03:37
-
-
Save leosuncin/ea36f65fe73c7de70b56964a39620ca5 to your computer and use it in GitHub Desktop.
Call a bash script from a node.js script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const { spawn } = require("child_process"); | |
const procesoHijo = spawn("bash", ["script.sh", "1", "+", "3"]); // Planto la semilla de la planta de tomates | |
let salida = []; | |
procesoHijo.stdout.on("data", function leerSalida(data) { // Cosecho los resultados, cada tomate que da la planta | |
// Se llama cada vez que el proceso hijo imprime en la consola | |
salida.push(data); | |
}); | |
procesoHijo.on("close", function terminoElHijo() { // Hago la salsa con todos los tomates | |
// Se llama al finalizar la ejecucion del proceso hijo | |
console.info(salida.toString()); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "$@" | bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment