nodejs exec命令失败,没有有用的错误消息 [英] nodejs exec command failing with no useful error message

查看:1136
本文介绍了nodejs exec命令失败,没有有用的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是要执行的代码



    cp.exec("cc -Wall /tmp/test.c -o /tmp/test", function(e, stdout, stderr) {
        if (e) {
            var errorstr = "Compilation failed with the following error
"+ e.message.toString() client.send(errorstr) console.log(e, stdout, stderr) ee.prototype.removeAllListeners() } else if (stderr.length > 0) { client.send("Compilion finished with warnings\n"+ stderr + '\n') client.send('compiled') ee.prototype.emit('compiled') } else { client.send("Compilation successful") ee.prototype.emit('compiled') } })

'client'是socket.io的回调参数的参数。 'ee'是EventEmitter的一个实例

'client' is the argument of socket.io's callback argument. 'ee' is an instance of EventEmitter

出现问题。在运行代码时,回调表明该命令不成功。 console.log(e,stdout,stderr)是

Coming to the problem. On running the code, the callback says that the command was unsuccessful. console.log(e, stdout, stderr) is

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

/tmp/test.c是一个有效的C代码,在检查目录/ tmp时,我发现test.c是正确的,二进制'test'生成并在shell中运行,正确执行。所以我不明白为什么它会导致执行不成功。错误对象的信息也没有用。非常感谢一些帮助/解释

/tmp/test.c is a valid C code and on checking the directory /tmp , I find that test.c is proper and the binary 'test' is being generated and on running in a shell, is properly executed. So I dont understand why it is flagging unsuccessful execution. The error object's information is unhelpful too. Would appreciate some help/explanation

推荐答案

我有点担心控制台中的输出。

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

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

看起来不像是一个合适的JSON / JavaScript对象,尤其是 [错误:命令失败:] 部分;至少有一个逗号丢失。

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

建议:


  1. 从命令行运行命令并检查退出代码(使用 echo $?)。如果退出代码是!= 0,那么这意味着命令失败(无论这意味着什么)。

  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).

当命令失败时, nodejs表示会将退出代码放入 e.code (其中我的输出中缺少...)。找出这个值发生了什么。

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.

尝试如果(e!== null)而不是如果(e)中不应该有所作为。

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

不要直接调用编译器,而是调用重定向stderr / stdout的shell脚本到文件(或使用 cc ... |& tee /tmp/cc.log 保存副本)以确保复杂设置的任何部分都不会吞下重要信息。

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.

这篇关于nodejs exec命令失败,没有有用的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆