Launching a web browser from the Dart script command line

I would like to open the given URL from a small command-line application that I wrote in Dart. Any easy way to do this? It will be like looking at the desktop (URI) in Java.

+5
source share
3 answers

Try this code:

import "dart:io"; void runBrowser(String url) { var fail = false; switch (Platform.operatingSystem) { case "linux": Process.run("x-www-browser", [url]); break; case "macos": Process.run("open", [url]); break; case "windows": Process.run("explorer", [url]); break; default: fail = true; break; } if (!fail) { print("Start browsing..."); } 
+2
source

You need to run it using Process.run() or Process.start() , and you have to take care of the OS differences yourself.

on sale - Linux you can use Linux: command to open the URL in the browser by default (must be installed, but it is usually the default)
- Windows https://superuser.com/questions/36728/can-i-launch-urls-from-command-line-in-windows
- OSX http://osxdaily.com/2011/07/18/open-url-default-web-browser-command-line/

+3
source

Call the default browser on Windows:

 Process.run("start", [url], runInShell: true); 

(Tested on Windows 7, although I'm afraid)

+1
source

Source: https://habr.com/ru/post/1233289/


All Articles