0

My Brackets extension wants to send data to its node process repeatly. like:

 #include <stdio.h>
int main(){
  int a,b;
  while(scanf("%d %d", &a, &b)!=EOF)
    printf("%d\n",a+b);
  return 0;
}

I know in pure node I can just write:

var exec = require('child_process').exec;
var ch = exec('./a.out');
process.stdin.pipe(ch.stdin);       
ch.stdout.pipe(process.stdout);  
ch.stderr.pipe(process.stdout);

but in Brackets, NodeDomain.prototype.exec() did not return a ChildProcess object. Is there any way I can achieve this?

somethin
  • 115
  • 6

1 Answers1

0

Yes, the Brackets NodeDomain doesn't return a ChildProcess to the Brackets code (for example your main.js).
But it does save it in the domain, so you could exec a different command in the domain to send data to the ChildProcess:

var child;
var childProcess = require("child_process");
function start() {
    child = exec('./a.out');
}
function send(data) {
    // Send data to the child
    // process.stdin.pipe(child.stdin); 
}
domainManager.registerCommand("domain", "start", start);
domainManager.registerCommand("domain", "send", send);
hirse
  • 2,394
  • 1
  • 22
  • 24