[英]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.