Created
March 20, 2017 20:05
-
-
Save geoffreyp/9a623d9f3aae0c27ec803475fe39c5e0 to your computer and use it in GitHub Desktop.
Communication entre NodeJS et un programme écrit en C
This file contains 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
const exec = require('child_process').exec; | |
// On éxécute le programme C | |
const process = exec('./a.out'); | |
// Envoie d'un message au programme C | |
process.stdin.write('Message envoyé au programme C depuis app.js'); | |
// écoute le programme C et affiche les données reçu | |
process.stdout.on('data', function (data) { | |
console.log("NodeJS receive : "+data.toString().trim()); | |
}); | |
This file contains 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
#include <stdio.h> | |
int main() { | |
int n; | |
char buf[255]; | |
// On écoute la sortie standart | |
n = read(0,buf,sizeof(buf)); | |
// Quand on a reçu quelque chose on le renvoie sur la sortie standart | |
write(1,"Program C receive : ",20); | |
write(1,buf,n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment