节点`require('child_process')。exec`非常严重地失败

时间:2019-03-12 06:36:50

标签: node.js linux macos shell openvpn

问题

模块exec

child_process函数在执行openvpn --version时引发错误。当我将命令更改为zsh --versionecho $(openvpn --version)之类的命令时,不会发生此错误。

此外,直接在shell上执行openvpn --version时没有错误出现。

代码

const util = require('util');
const exec = util.promisify(require('child_process').exec);

(async () => {
    const cmd = 'openvpn --version'
    try {
        const {stdout, stderr} = await exec(cmd);
        console.log(stdout);
    } catch (err) {
        console.error(err);
    }
})();   

输出

{ Error: Command failed: openvpn --version

    at ChildProcess.exithandler (child_process.js:297:12)
    at ChildProcess.emit (events.js:197:13)
    at maybeClose (internal/child_process.js:984:16)
    at Socket.stream.socket.on (internal/child_process.js:401:11)
    at Socket.emit (events.js:197:13)
    at Pipe._handle.close (net.js:611:12)
  killed: false,
  code: 1,
  signal: null,
  cmd: 'openvpn --version',
  stdout: 'OpenVPN 2.4.6 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Sep  3 2018\nlibrary versions: OpenSSL 1.1.1  11 Sep 2018, LZO 2.10\nOriginally developed by James Yonan\nCopyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net>\nCompile time defines: enable_async_push=no enable_comp_stub=no enable_crypto=yes enable_crypto_ofb_cfb=yes enable_debug=yes enable_def_auth=yes enable_dependency_tracking=no enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown enable_fast_install=needless enable_fragment=yes enable_iproute2=yes enable_libtool_lock=yes enable_lz4=yes enable_lzo=yes enable_maintainer_mode=no enable_management=yes enable_multihome=yes enable_pam_dlopen=no enable_pedantic=no enable_pf=yes enable_pkcs11=yes enable_plugin_auth_pam=yes enable_plugin_down_root=yes enable_plugins=yes enable_port_share=yes enable_selinux=no enable_server=yes enable_shared=yes enable_shared_with_static_runtimes=no enable_silent_rules=no enable_small=no enable_static=yes enable_strict=no enable_strict_options=no enable_systemd=yes enable_werror=no enable_win32_dll=yes enable_x509_alt_username=yes with_aix_soname=aix with_crypto_library=openssl with_gnu_ld=yes with_mem_check=no with_sysroot=no\n',
  stderr: '' }

环境

  • ubuntu 18.10。 Openvpn由apt install openvpn
  • 安装
  • macOS High Sierra。 Openvpn由brew install openvpn
  • 安装
  • 节点v11.11.0

0 个答案:

没有答案