Run an external execution file in Xojo

Hello,

I’m trying to run (call?) an external execution file using Shell command. Using the following codes, it runs fine on Windows system.

system.EnvironmentVariable(“PATH”)=system.EnvironmentVariable(“PATH”)+“C:/Users/username/appfolder”
sh.TimeOut=-1
sh.Execute(“myapp”)

However, when I do similar coding for MacOS as below, it doesn’t run.

system.EnvironmentVariable(“PATH”)=system.EnvironmentVariable(“PATH”)+":/Users/username/appfolder"
sh.Mode=0
sh.Execute(“myapp”)

My app runs okay on Terminal with the same setting of path though. I searched and searched on the web to get some help but not successful so far… If anyone can shed me some light, much appreciated!

Hi,
If the problem is just want to execute the file in documents folder, you can try this code, its running both mac and linux.

dim xfile as FolderItem
xFile = SpecialFolder.UserHome.Child("Documents").Child("test.app")
if xfile <> nil and xfile.Exists then
  xFile.Permissions = Val( "&o" +"777")
end if
xfile.Launch

thanks
regards,
arief

MacOS Terminal commands descriptions are available with help, Man, etc. and on Apple web (a search is needed for the URL).

Nota: your code use curly quotes (maybe the forum software changed the standard quotes)…

Instead of trying to alter the environment, have you tried just passing the full path to Execute?

Also… the path you’re adding isn’t valid on macOS, nor on Windows:

c:/Users/username/appfolder

It looks like you took a windows path and just replaced \ with / and that’s not going to work on either platform.

1 Like

Instead, use:


xFile = SpecialFolder.Documents.Child("test.app")

Explanations here:
http://documentation.xojo.com/api/files/specialfolder.html

You’re right. I was confused when I wrote the code here but the actual path was written correct in both Mac and Windows. Thanks!