Vba 节点命令通过自定义外壳函数退出,带有32512

Vba 节点命令通过自定义外壳函数退出,带有32512,vba,macos,excel,Vba,Macos,Excel,我试图在Excel宏中使用VBA运行节点命令,在的帮助下,我得出以下结论: Private Declare PtrSafe Function popen Lib "libc.dylib" (ByVal command As String, ByVal mode As String) As LongPtr Private Declare PtrSafe Function pclose Lib "libc.dylib" (ByVal file As LongPtr) As Long Private

我试图在Excel宏中使用VBA运行节点命令,在的帮助下,我得出以下结论:

Private Declare PtrSafe Function popen Lib "libc.dylib" (ByVal command As String, ByVal mode As String) As LongPtr
Private Declare PtrSafe Function pclose Lib "libc.dylib" (ByVal file As LongPtr) As Long
Private Declare PtrSafe Function fread Lib "libc.dylib" (ByVal outStr As String, ByVal size As LongPtr, ByVal items As LongPtr, ByVal stream As LongPtr) As Long
Private Declare PtrSafe Function feof Lib "libc.dylib" (ByVal file As LongPtr) As LongPtr

Function execShell(command As String, Optional ByRef exitCode As Long) As String
    Dim file As LongPtr
    file = popen(command, "r")

    If file = 0 Then
        Exit Function
    End If

    While feof(file) = 0
        Dim chunk As String
        Dim read As Long
        chunk = Space(50)
        read = fread(chunk, 1, Len(chunk) - 1, file)
        If read > 0 Then
            chunk = Left$(chunk, read)
            execShell = execShell & chunk
        End If
    Wend

    exitCode = pclose(file)
End Function

Sub RunTest()
    Dim result As String
    Dim exitCode As Long
    result = execShell("node -v", exitCode)
    Debug.Print "Result: """ & result & """"
    Debug.Print "Exit Code: " & Str(exitCode)
End Sub
但是当我运行
RunTest()
时,我得到了这个错误的响应:

Result: ""
Exit Code:  32512
虽然它应该返回如下内容:

Result: "v8.4.0"
Exit Code:  0

有些地方出了问题,但我找不到任何关于什么地方出了问题以及如何解决问题的清晰见解。其他命令,如
whoami
ls
echo
在我尝试它们时,会按照预期工作。

如果调用
node
而不是
node-v
,会发生什么?@jsotola同样的事情。