0

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.

spidey
  • 121
  • 1
  • 2
  • 15
  • For first attempt, it's working for you ? – Mihai Alexandru-Ionut Jan 20 '18 at 21:59
  • Possible duplicate of [Execute an exe file using node.js](https://stackoverflow.com/questions/19762350/execute-an-exe-file-using-node-js) – Mihai Alexandru-Ionut Jan 20 '18 at 22:01
  • Your C# application is crashing, you aren't passing any argument and you're exceeding the size of args[]. – Gusman Jan 20 '18 at 22:01
  • Also keep in mind on the web server acct u might have very limited permission ..so the exe that otherwise works might fail in that context – Ctznkane525 Jan 20 '18 at 22:07
  • thanks for suggestions! Now I am able to invoke C# exe from Node. Still have some doubts about how I can send data back to node js from exe. e.g. I want to send file stream back to nodejs. At present whatever is written in console.writeline is sent as output to node. (Updated the questions) – spidey Jan 20 '18 at 23:01

0 Answers0