使用nodejs操作cmd命令,为什么重启node时都会返回一段字符串?
发布于 7 年前 作者 caihuattkl 3484 次浏览 来自 问答

使用nodejs操作cmd命令,为什么重启node时都会返回一段字符串?这段文本是什么意思? (node:6440) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 7761726e696e673a204c462077696c6c206265207265706c616365642062792043524c4620696e206175746f4e6f64652f7365727665722e6a732e0a5468652066696c652077696c6c206861766520697473206f726967696e616c206c696e6520656e64696e677320696e20796f757220776f726b696e67206469726563746f72792e0a (node:6440) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

另外还有一个问题.例如我通过node的 const exec = require(‘child_process’).exec; exec(cli, {encoding: ‘hex’}, function(err, stdouts,stderr)… 回调中返回3个参数,1一个是命令执行错误的返回,stdouts是成功的参数…假如我现在使用这个exec执行一条命令为’'git add -A" 将所有的文件加入到本地git中,但是这条命令执行后是没有返回的.没有返回就表示执行成功了.那我在node的控制台中怎么知道他是执行成功的呢?怎么判断呢?使用空字符串无法判断啊?换句话说,就是我想知道’git add -A’这条命令到底执行成功没有?怎么知道呢?

1 回复
回到顶部