in Linux I use (to see if it is installed and where it is)
dim sh as new shell
sh.Execute ("which ffmpeg")
if sh.Result = "" then
MsgBox "ffmpeg not found"
else
MsgBox "ffmpeg found at " + sh.Result.Replace(EndOfLine, "")
end if
In OSX ‘which’ does not work in a Xojo Shell, I don’t know why
most command tools should (in OSX at least) be in usr/bin or one of its branches
FUNCTION find_app(app_name as string) as folderitem
Dim f As FolderItem
#If TargetMacOS Then
f=Volume(0).child("developer")
If f<>Nil Then f=f.child("usr")
If f<>Nil Then f=f.child("bin")
If f<>Nil Then f=f.child(app_name)
If f<>Nil Then
If Not f.Exists Then f=Nil
End If
//
//
If f=Nil Then
f=Volume(0)
If f<>Nil Then f=f.child("usr")
If f<>Nil Then f=f.child("bin")
If f<>Nil Then f=f.child(app_name)
End If
If f<>Nil Then
If Not f.Exists Then f=Nil
End If
//
//
If f=Nil Then
f=SpecialFolder.Applications
End If
If f<>Nil Then
If Not f.Exists Then f=Nil
End If
//
//
#Else
f=Nil
#EndIf
Return f
END FUNCTION
this is what I use to find things the XCODE, SWIFT, SIPS and other command line tools
This uses the same rules and API that cmd.exe uses to find executables by name:
Function LocateOnPath(ProgramName As String) As FolderItem
Soft Declare Function PathResolve Lib "Shell32" (Path As Ptr, StartDir As Ptr, Flags As Integer) As Boolean
Const PRF_REQUIREABSOLUTE = &h0010
Const PRF_VERIFYEXISTS = &h0001
Dim resolv As New MemoryBlock(255)
resolv.WString(0) = ProgramName
If Not PathResolve(resolv, Nil, PRF_REQUIREABSOLUTE Or PRF_VERIFYEXISTS) Then Return Nil
Return GetFolderItem(resolv.WString(0), FolderItem.PathTypeAbsolute)
End Function
[quote=278766:@Norman Palardy]Use the full path
/usr/bin/which[/quote]
This is the way that I’ve always done it, it’s harder for a nefarious application to replace core system apps; but by using a ‘search’ function you may not get the correct version or even the correct tool.
Sub findCLI(cli as string)
dim sh as new shell
sh.Execute ("if command -v " + cli + " > /dev/null 2>&1; then echo " + cli + " is available; else echo " + cli + " is not available; fi")
MsgBox (sh.Result)
End Sub
[quote=278819:@Axel Schneider] dim sh as new shell
sh.Execute (“if command -v " + cli + " > /dev/null 2>&1; then echo " + cli + " is available; else echo " + cli + " is not available; fi”)
MsgBox (sh.Result)[/quote]
sorry… it seems to suffer the same issue as “Which” in that is doesn’t look in /usr/local
but thanks
if TextField1.Text.Len > 0 then
dim MyShell as new shell
dim cmd as string
dim MyResult as string
cmd ="whereis " + TextField1.Text
MyShell.Execute(cmd)
MyResult = MyShell.Result
if MyResult.len > 0 then
MsgBox “CMD «” + TextField1.Text + “» is available”
TextField2.Text = MyResult
else
MsgBox “CMD «” + TextField1.Text + “» is NOT available”
TextField2.Text = “”
end if
end if