I am using the Excel vba execShell script from here to pull data from a web server using curl in Excel for Mac. It works very well on my own Mac (and a number of other Macs that I have been testing on).
However, on a friends Mac (same (latest) version of Mac OS and Excel 365) it fails. It seems that on his Mac the execShell returns empty strings.
I simplified the script and only run an echo
command and experience the same behavior. This is the test script I am running
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
On my Mac, test_command shows
Value_returned
0
on his Mac it only shows
0
result = ""
returns True
.
Any ideas what may cause this behavior?
Any workaround that does not require updates on my friends OS?
Thanks a lot.