Using JS to create C# child process which passes data back to the JS process

32 views Asked by At

I am writing a C# process that performs some execution and returns a stream of bytes back to the JS process.

My JS Code:

    const gameServerProcess = cp.spawn('./Process.x86_64', [],
        {
            encoding: 'utf8',
            maxBuffer: Number.MAX_VALUE
        });

    gameServerProcess.stdout.on('data', (data) => {
        console.log(`stdout: ${data}`);
    });

My C# Code:

    GZipStream zip = new GZipStream(Console.OpenStandardOutput(), CompressionMode.Compress);
    StreamWriter streamWriter = new StreamWriter(zip);
    streamWriter.Write(json);
    streamWriter.Close();
    zip.Close();

The stdout.on steam is receiving the desired output but it is also receiving the logs from the process. The trouble I am having is understanding how best to determine what output is a log and what output is the process result data.

The cleanest solution seemed to be using options.stdio to open a 4th output stream for the process which would only be used to pass the desired output data https://nodejs.org/api/child_process.html#optionsstdio . The problem I am having with that is I dont know how to write to that 4th output steam from C#. Is this possible? Is there a better solution that I am missing?

Thanks for the help!

0

There are 0 answers