繁体   English   中英

我怎样才能看到作为命令行 arguments 传递的 Node.js 到底是什么?

[英]How can I see what EXACTLY is Node.js passing as command line arguments?

在 windows 上通过 Node 的execFile运行命令是一场噩梦。 很多时候,如果我从错误中复制“失败”命令,则会收到“命令失败”错误,它执行得很好。 有时,尝试windowsVerbatimArguments: true会有所帮助,但通常不会。

例如,现在我正在运行 Visual Studio 的 MSBuild.exe,在 Node.js 中使用以下参数 - 我已经打印了传递给execFile的确切数组:

Running MSBuild with parameters:  [
  'D:\\PROJECT\\vcxproj\\HelperProject.vcxproj',
  '-t:OutputBuildMacro',
  '-p:ProjectToImport=D:\\PROJECT\\vcxproj\\HelperProject.vcxproj;PropertyToGet="OutputType,BlueProjectsVersionPropsGlobalIncluded"'
]
Executable path:  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe

如果我从数组中复制这些项目并将它们粘贴到命令行中,它将运行得很好。 显然,Node.js 在传递命令时搞砸了。 因为这种情况在我身上发生过很多次,就在几周前,我使用 Irfan View,我并没有为这个特定问题寻找解决方案——我很快就会再次提出类似的问题。

我正在寻找指南如何查看 Node.js实际传递的内容,以便我可以猜测如何编辑参数以便它们被我调用的命令接受。

如何查看 Node.js到底是什么,为什么我调用execFile

您可以使用NODE_DEBUG环境变量从 NodeJS 中获取额外信息。

你可以在这里找到文档。

例如这个 index.js:

const { execFile } = require('child_process');

execFile('/bin/ls', ['/Volumes'], {}, (err, stdout, stderr) => {
    if (err) {
        console.error('Command failed');
    } else {
        console.log('Command succeded');
    }
});

并为child_process模块启用调试日志记录,请执行:

NODE_DEBUG=CHILD_PROCESS node index.js

(在 Windows 上,环境变量的设置似乎不同)

set NODE_DEBUG=CHILD_PROCESS & node index.js

就我而言,它会产生这种 output:

CHILD_PROCESS 85208: spawn {
  cwd: null,
  env: null,
  gid: undefined,
  uid: undefined,
  shell: false,
  windowsHide: false,
  windowsVerbatimArguments: false,
  args: [ '/bin/ls', '/Volumes' ],
  detached: false,
  envPairs: [
    'COMMAND_MODE=unix2003',
    ...
    'TERM=xterm-256color',
    'NODE_DEBUG=CHILD_PROCESS',
  ],
  file: '/bin/ls'
}

附言

设置NODE_DEBUG=*将生成 NodeJS 中可用的所有调试日志信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM