Reputation: 2767
I want to compile C program using Nodejs child process.
C .out file execute function:
var exec= require('child_process').exec;
exec("test.exe",function(err,stdout,stdin){
//call back handling code here
});
C program :
#include <stdio.h>
int main()
{
char msg[8];
scanf("Please endter %s",&msg)
printf("Hello world %s\n", msg);
return 0;
}
How to pass runtime scanf input arguments to child process?
Upvotes: 1
Views: 1443
Reputation: 106696
scanf()
reads from stdin
. Try these:
node script:
var exec = require('child_process').exec;
var cp = exec('test.exe', function(err, stdout, stderr) {
process.stdout.write(stdout);
process.stderr.write(stderr);
});
cp.stdin.end('node.js');
C program:
#include <stdio.h>
int main()
{
char msg[8];
scanf("%7s", msg);
printf("Hello world %s\n", msg);
return 0;
}
This outputs: Hello world node.js
Upvotes: 3