2

It is possible to run URL or path with external program from Haxe?

Something like a Process.Start("C:\") in C# will be opened drive C in file windows explorer (or Process.Start("/home/user/Desktop") will open Caja with this path in Linux Mint), or somethink like a package "Open" in NodeJS (it will do the same).

Or I need to open some text file with text editor, what selected in system by default. Or when I try to run URL, then must be opened default web-browser with this address.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
Red Null
  • 143
  • 8

1 Answers1

4

I think I can do this little code:

public static function execUrl (url:String) : Void {
    switch (Sys.systemName()) {
        case "Linux", "BSD": Sys.command("xdg-open", [url]);
        case "Mac": Sys.command("open", [url]);
        case "Windows": Sys.command("start", [url]);
        default:
    }
}

in unix-like systems can be used program "xdg-open". it know how to run needed path/url, and in windows this can do program "start"

Andy Li
  • 5,894
  • 6
  • 37
  • 47
Red Null
  • 143
  • 8
  • For completeness, we can use `Sys.command("open", [url]);` on Mac. – Andy Li Apr 25 '16 at 04:04
  • This doesn't seem like it does anything when you run your app on Android. `Sys.systemName()` returns `Linux` but `Sys.command(...)` doesn't launch the browser. – ashes999 Mar 02 '17 at 05:47
  • Maybe xdg-open is not available on Android, see example here: http://forum.kodi.tv/showthread.php?tid=235733 – Red Null Mar 03 '17 at 11:19