0

I am stuck on a NodeJS error while trying to execute a script and get the output of it.

I get the following error :

TypeError: invalid data
    at WriteStream.Socket.write (net.js:623:11)
    at Object.execFileSync (child_process.js:482:20)
    at doRender (/test/apps/application/routes/TEST.js:1786:26)

I guess it comes from a misuse of the NodeJS native execFileSync function, but I've tried a lot of things to match the documentation without any success so far.

Here is my code :

router.get("/stat", authReader, function (req, res) {

    //Current file is in application/routes

    var doRender = function (req, res) {

        var output;

        //I want to execute application/scripts/test.bash

        output= child_process.execFileSync("test.bash",[], {
            cwd: "../scripts"
        });

        result= processDataFromCSV(output);


        //processing data in response
        res.render(acronym + "_test", {
            title: "CSV output",
            result: result,
        });
    }

    doRender(req, res);
}

Could you please help me to understand what I am doing wrong ? Any help is greatly appreciated.

The Once-ler
  • 220
  • 3
  • 16

1 Answers1

0

Verify that your test.bash is executable, or run it like /bin/bash test.bash using child_process.execSync(). For more information look at this answer by Sravan here;

Eds
  • 36
  • 3
  • Thank you for your answer. I did what you suggested and ran my script test.bash using /bin/bash: it worked fine. I am afraid my problem comes from the parameters I give to execFileSync, but, although I keep reading the Node documentation about it, I am still stuck with this issue. – The Once-ler Feb 23 '18 at 09:12