Excel Mac OS libc.dylib popen不返回任何数据

问题描述

我正在使用http://www.lfd.uci.edu/~gohlke/pythonlibs/中的Excel vba execShell脚本使用Excel for Mac中的curl从Web服务器提取数据。它在我自己的Mac(以及我已经测试过的许多其他Mac)上都能很好地工作。

但是,在朋友Mac(相同(最新)版本的Mac OS和Excel 365)上,它会失败。似乎在他的Mac上,execShell返回空字符串。

我简化了脚本,仅运行echo命令并遇到相同的行为。这是我正在运行的测试脚本

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(ByVal 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 test_command()
    Dim errorCode As Long
    result = execShell("echo Value_returned",errorCode)
    msgBox(result & " " & errorCode)
    
End Sub

在我的Mac上,显示test_command

Value_returned 
0 

在他的Mac上仅显示

0

result = ""返回True

任何想法可能会导致这种行为吗?

不需要在我的朋友操作系统上进行更新的任何解决方法吗?

非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)