0

I am trying to establish IPC between Node and Console app written in .NET 6 on macOS. It launches the Application, however, cannot perform the IPC.

Once Console app is launched, I can write to console and that is received correctly, however, whatever is sent by Node App is not received by Console App.

Following is the code

Node

var spawn = require('child_process').spawn;
var ipc = spawn('open',['./console-app-demo']);
ipc.stdin.setEncoding('utf8');
ipc.stderr.on('data', function(data) {process.stdout.write(data.toString()};
ipc.stdout.on('data', function(data) {process.stdout.write(data.toString()};
ipc.stdin.write(JSON.stringify({message: 'hello world'}));

C#

static void Main(string[] args) 
{
  Console.WriteLine("hello world from .Net 6");
  Thread t = new Thread(TestIPC);
  t.Start();
  Console.ReadLine();
}

static void TestIPC()
{
  var input = Console.OpenStandardInput();
  var buffer = new byte[512];
  int length;
  while(input.CanRead && (length = input.Read(buffer, 0, buffer.Length)) 
  {
    var payload = new byte[length];
    Buffer.BlockCopy(buffer, 0, payload, length);
    Console.Write("received: " + Encoding.UTF8.GetString(payload));
    Console.Out.Flush();
  }
}

I could enter the Console that is opened and write message that gets printed back as received by .Net Application. Node script resides in the same folder as the console-app-demo.

Will appreciate any suggestion.

vibhu
  • 1,657
  • 2
  • 15
  • 19
  • the issue was with the construct of spawn that I had used, it should be var ipc = spawn(['./console-app-demo']); – vibhu Mar 31 '23 at 13:31

0 Answers0