'Electron/C# error when calling child process

I am building an application in electron and I am trying to execute a console application which I build in C#. This console application receives a json string as a command line arguments to generate a RDLC report and automatically sends it to the default printer.

The console application works as expected when I execute it from the command line. But then I try to execute it by calling it from my electron application I am getting the following error:

An error ocurred during local report processing.

I am using the following code from my electron application to spawn the child process.

const {spawn} = require('child_process');
let child;
let stdoutChunks = '';

let replyPayload = {
    success: true,
    message: ''
}

try
{
    child = spawn(path.join(__dirname, '../../../invoice/invoice.exe'), [parameter]);
}catch(err){
    replyPayload.success = false;
    replyPayload.message = 'An unexpected error ocurred.';
    event.reply(args.method, replyPayload)
}

child.stdout.on('data', (data) => {
    stdoutChunks += data;
});

child.stdout.on('end', function() {

    try
    {
        if(stdoutChunks.trim().length !== 0)
        {            
            var info = JSON.parse(stdoutChunks);

            if(info.success === false) {                
                replyPayload.success = false;
                replyPayload.message = info.message;
                event.reply(args.method, replyPayload);
            }

            event.reply(args.method, replyPayload);
        }

    }catch(err) {
        replyPayload.success = false;
        replyPayload.message = err.stack;
        event.reply(args.method, replyPayload)
    }
});

child.stderr.on('data', (data) => {
    replyPayload.success = false;
    replyPayload.message = '[1] - An error ocurred while invoice printing.';
    event.reply(args.method, replyPayload);
});

child.on('exit', function (code) {
    if(code !== 0 && code !== null) {
        replyPayload.success = false;
        replyPayload.message = '[2] - An error ocurred while invoice printing.';
        event.reply(args.method, replyPayload);
    }
});

I am not sure if there is something from the environment that is used when executing the application from a command line that is different when the application is spawned as a child process from nodejs.

When the console application is executed this way it works correctly



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source