命令有效,但也会出现“命令失败”

时间:2019-03-30 17:53:11

标签: node.js exec

我在Node.js应用程序中运行的某些命令有些奇怪。
我的代码:

const exec = require('child_process').exec;
return new Promise((resolve, reject) => {
    try {
        exec(fullCommand, (error, stdout, stderr) => {

            // Resolve the result parameters.
            resolve({
                error: error,
                stdout: stdout,
                stderr: stderr
            });
        });
    } catch (error) {

        // If any exception, return a reject.
        reject(false);
    }
});

我跑步时:

npm outdated --prefix C:\test\test\Web\test\WebVisualizer\client

当我处理错误,stdout和stedrr时,我得到了完整的结果:

error:
{ Error: Command failed: npm outdated --prefix C:\test\test\Web\test\WebVisualizer\client

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:189:13)
    at maybeClose (internal/child_process.js:970:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
  killed: false,
  code: 1,
  signal: null,
  cmd:
   'npm outdated --prefix C:\\test\\test\\Web\\test\\WebVisualizer\\client' }

stdout:
Package                        Current          Wanted  Latest  Location
@babel/core                      7.2.2           7.2.2   7.4.0  client
babel-core              7.0.0-bridge.0  7.0.0-bridge.0  6.26.3  client
babel-eslint                     9.0.0           9.0.0  10.0.1  client
babel-jest                      23.6.0          23.6.0  24.5.0  client
css-loader                       1.0.0           1.0.0   2.1.1  client
dotenv                           6.0.0           6.0.0   7.0.0  client
dotenv-expand                    4.2.0           4.2.0   5.1.0  client
eslint                          5.12.0          5.12.0  5.16.0  client
eslint-loader                    2.1.1           2.1.1   2.1.2  client
eslint-plugin-flowtype          2.50.1          2.50.1   3.4.2  client
eslint-plugin-import            2.14.0          2.14.0  2.16.0  client
eslint-plugin-jsx-a11y           6.1.2           6.1.2   6.2.1  client
file-loader                      2.0.0           2.0.0   3.0.1  client
html-webpack-plugin      4.0.0-alpha.2   4.0.0-alpha.2   3.2.0  client
jest                            23.6.0          23.6.0  24.5.0  client
jest-pnp-resolver                1.0.2           1.0.2   1.2.1  client
jest-resolve                    23.6.0          23.6.0  24.5.0  client
pnp-webpack-plugin               1.2.1           1.2.1   1.4.1  client
postcss-preset-env               6.5.0           6.5.0   6.6.0  client
react                           16.8.4          16.8.6  16.8.6  client
react-dom                       16.8.4          16.8.6  16.8.6  client
react-router-dom                 4.3.1           4.3.1   5.0.0  client
terser-webpack-plugin            1.2.2           1.2.2   1.2.3  client
webpack                         4.28.3          4.28.3  4.29.6  client
webpack-dev-server              3.1.14          3.1.14   3.2.1  client
workbox-webpack-plugin           3.6.3           3.6.3   4.1.1  client


我在这里做错了什么?该命令有效,但我仍然看到错误...

更新
我还在客户端项目中得到了一些奇怪的文件(我从未见过的exe文件)。

0 个答案:

没有答案