nodejs exec command failing with no useful error message

前端 未结 1 2012
执念已碎
执念已碎 2021-02-19 21:29

This is the code to execute



    cp.exec(\"cc -Wall /tmp/test.c -o /tmp/test\", function(e, stdout, stderr) {
        if (e) {
            var errorstr = \"Comp         


        
相关标签:
1条回答
  • 2021-02-19 22:16

    I'm a bit worried about the output in the console.

    { [Error: Command failed: ] killed: false, code: false, signal: undefined }
    

    doesn't look like a proper JSON/JavaScript object, especially the [Error: Command failed: ] part; there is at least a comma missing.

    Suggestions:

    1. Run the command from the command line and check the exit code (use echo $?). If the exit code is != 0, then this means the command "failed" (whatever that might mean).

    2. When the command fails, nodejs says it will put the exit code into e.code (which I'm missing in your output...). Find out what happened to this value.

    3. Try if(e !== null) instead of if(e). Shouldn't make a difference, though.

    4. Instead of calling the compiler directly, call a shell script which redirects stderr/stdout to a file (or save a copy using cc ... |& tee /tmp/cc.log) to make sure no part of the complex setup swallows important information.

    0 讨论(0)
提交回复
热议问题