Shell in High Sierra 10.13.5

I have built a Xojo program that runs some shell scripts. It was built and works in 10.10.5 system. I had to define the system path in the app.Open event to get the shell script to work in 10.10.5

Dim origPath As String = System.EnvironmentVariable("PATH") System.EnvironmentVariable("PATH") = "/usr/local/bin:" + origPath
A colleague who is on High Sierra 10.13.5 cannot get the the shell scripts to run, they return “command not found”.

Do I need to define a different system path for High Sierra?

Did you have a look if the command is there?

Your best off supplying the full ShellPath to the cli tool your executing from the Shell class

The PATH is not within the Shell Class defined, or at least not fullyas i expect

You can have them check the path by going to a terminal and typing

which <commandname>

It’ll return the full path of the command if it exists.

Yes it is. The user can use the command directly in Terminal and it works.

@Greg O’Lone
The path will differ depending on the level of OS the user is running.

[quote=396123:@Malcolm Wooden]@Greg O’Lone
The path will differ depending on the level of OS the user is running.[/quote]

…and therefore you call the “which” command to get the path on that machine.

To find the path to a tool from within Xojo:

Private Function FindCliApp(cli As String) as FolderItem
  dim f as FolderItem
  #if TargetMacOS or TargetLinux then
    dim sh as new shell
    sh.Execute "/bin/bash -lc " + ShellQuote("which " + cli.Trim)
    if sh.ErrorCode = 0 then
      dim path as string = sh.Result
      path = ReplaceLineEndings(path, EndOfLine).Trim
      path = path.NthField(EndOfLine, path.CountFields(EndOfLine))
      f = new FolderItem(path, FolderItem.PathTypeNative)
    end if
    #pragma unused cli
  return f
End Function

Private Function ShellQuote(s As String) as String
  s = s.ReplaceAll("'", "'\\''")
  s = "'" + s + "'"
  return s
End Function

Simply put - the Xojo Shell class does NOT inherit the normal Terminal environment. Anything that you want to access on Mac OS will require the full NativePath.

I build a list of my app’s external commands and set constants like:

chmodbin = “/bin/chmod”

I then call out to the command with something like:

theShell.Execute “”"" + chmodbin + “”" " + theArgs + "

Many thanks to all you guys who helped with replies particularly @Kem Tekinay who’s answer was spot on.

Many thanks.