Skip to content

使用nodejs的 child_process.exec(Sync) 执行 qshell get <Bucket> <Key> [-o <OutFile>]下载成功但会以非0退出 #372

@Koppel-Zhou

Description

@Koppel-Zhou

问题描述

使用nodejs的 child_process.exec(Sync) 执行 qshell get [-o ]下载成功但会以非0退出

重现步骤

const { execSync } = require('child_process');
execSync(qshell get <Bucket> <Key> [-o <OutFile>]);

执行以上代码会出现如下错误

Error: Command failed: qshell get <bucket> "***********" --outfile="*************" --remove-temp-while-error=true 
    at checkExecSyncError (child_process.js:760:11)
    at execSync (child_process.js:833:15)
    at runCommand (/Volumes/code/sc-mce-pc-teacher/src/utils/NodeEnv.js:76:3)
    at Object.<anonymous> (/Volumes/code/sc-mce-pc-teacher/.bin/notarize:37:1)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  status: 1,
  signal: null,
  output: [
    null,
    Buffer(8945) [Uint8Array] [
       91,  73,  93,  32,  32,  68, 111, 119, 110, 108, 111,  97,
      100,  32,  91, 104, 117, 111, 104, 117,  97,  58, 111, 110,
      108, 105, 110, 101,  47, 115,  99,  45, 109,  99, 101,  45,
      112,  99,  45, 116, 101,  97,  99, 104, 101, 114,  45, 115,
      105, 103, 110, 101, 100,  45, 102, 111, 114, 116, 101, 115,
      116,  47,  49,  57,  51,  48,  52,  55,  56,  47,  86, 105,
      115, 112,  97, 114, 107,  32,  67, 108,  97, 115, 115, 114,
      111, 111, 109,  45,  49,  46,  48,  46,  52,  46, 100, 109,
      103,  93,  32,  61,
      ... 8845 more items
    ],
    Buffer(0) [Uint8Array] []
  ],
  pid: 75398,
  stdout: Buffer(8945) [Uint8Array] [
     91,  73,  93,  32,  32,  68, 111, 119, 110, 108, 111,  97,
    100,  32,  91, 104, 117, 111, 104, 117,  97,  58, 111, 110,
    108, 105, 110, 101,  47, 115,  99,  45, 109,  99, 101,  45,
    112,  99,  45, 116, 101,  97,  99, 104, 101, 114,  45, 115,
    105, 103, 110, 101, 100,  45, 102, 111, 114, 116, 101, 115,
    116,  47,  49,  57,  51,  48,  52,  55,  56,  47,  86, 105,
    115, 112,  97, 114, 107,  32,  67, 108,  97, 115, 115, 114,
    111, 111, 109,  45,  49,  46,  48,  46,  52,  46, 100, 109,
    103,  93,  32,  61,
    ... 8845 more items
  ],
  stderr: Buffer(0) [Uint8Array] []
}
error Command failed with exit code 1.

或者

const { exec } = require('child_process');
exec(qshell get <Bucket> <Key> [-o <OutFile>], (error, stdout, stderr) => {
      stdout && console.log(stdout);
      stderr && console.error(stderr);
      error && console.error(error);
      error && process.exit(1);
    })

执行以上代码会出现如下错误

Error: Command failed: qshell get <bucket> "**************" --outfile="*************" --remove-temp-while-error=true 
    at checkExecSyncError (child_process.js:760:11)
    at execSync (child_process.js:833:15)
    at /Volumes/code/sc-mce-pc-teacher/src/utils/NodeEnv.js:77:5
    at new Promise (<anonymous>)
    at runCommand (/Volumes/code/sc-mce-pc-teacher/src/utils/NodeEnv.js:76:10)
    at fun (/Volumes/code/sc-mce-pc-teacher/.bin/notarize:37:9)
    at Object.<anonymous> (/Volumes/code/sc-mce-pc-teacher/.bin/notarize:39:1)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:75710) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:75710) [DEP0018] 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.

期望结果?

  • 下载成功以status为0成功退出

实际结果?

  • the Node.js process with a non-zero exit code.

错误日志/截图/配置参数

image

相关环境信息

  • 操作系统:macOS 13.0.1 (22A400)
  • qshell版本: qshell version v2.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions