Updating questing based on suggestions. Now I am able to invoke console app.
created C# console application as below:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(args[0]);
Console.WriteLine(args[1]);
Console.WriteLine(args[2]);
Console.WriteLine("random text");
// Want to invoke this from Node JS API endpoint. Also want to pass some parameters from Node JS. This method will have code
// to generate excel template.
}
}
}
Trying to invoke exe from nodejs like below
const exec = require('child_process');
const child = exec.execFile('ConsoleApplication1.exe', ['arg1', 'arg2', 'arg3'], function (error, stdout, stderr) {
if (error) {
throw error;
}
console.log(stdout);
});
after execution in node, I see condole.log(stdout) is printing all 4 values as below: arg1 arg2 arg3 random text
Thanks for suggestions! I have one followup question. I observed that, I have 4 lines of console.writeline in C# main method. Node return me these 4 strings in stdout. Is this how we suppose to get output from C# exe? e.g. if I remove all lines of code from main method in C# exe, node do not print anything.