I have a ruby script that does contains this line:
system("open '#{html_path}'")
html_path
is the path to a local .html
file. So the script opens a browser where I can normally inspect and view this file.
In contrast to a MacOS environment, this doesn't work in bash
of WSL. Running the script nothing happens, and when I execute the open
call in the console directly I get this:
sujan@LenovoX1:/mnt/c/Users/Jan/Documents/foo$ open Preview.html
Couldn't get a file descriptor referring to the console
I already investigated that open
does something different in Ubuntu and I should use see
or xdg-open
to open a file.
Unfortunately these also don't work in WSL:
sujan@LenovoX1:/mnt/c/Users/Jan/Documents/foo$ see ./Preview.html
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/%{ <-- HERE (.*?)}/ at /us
r/bin/see line 528.
Couldn't find a suitable web browser!
Set the BROWSER environment variable to your desired browser.
Warning: program returned non-zero exit code #1
and
sujan@LenovoX1:/mnt/c/Users/Jan/Documents/foo$ xdg-open ./Preview.html
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/%{ <-- HERE (.*?)}/ at /us
r/bin/run-mailcap line 528.
Couldn't find a suitable web browser!
Set the BROWSER environment variable to your desired browser.
Warning: program returned non-zero exit code #1
/usr/bin/xdg-open: 771: /usr/bin/xdg-open: www-browser: not found
/usr/bin/xdg-open: 771: /usr/bin/xdg-open: links2: not found
/usr/bin/xdg-open: 771: /usr/bin/xdg-open: elinks: not found
/usr/bin/xdg-open: 771: /usr/bin/xdg-open: links: not found
/usr/bin/xdg-open: 771: /usr/bin/xdg-open: lynx: not found
/usr/bin/xdg-open: 771: /usr/bin/xdg-open: w3m: not found
xdg-open: no method available for opening './Preview.html'
Thinking about it, this makes sense: There is no browser available inside WSL.
Can I somehow set this BROWSER
variable so see
works inside bash
of WSL?
Bonus question: If yes, how can I make the ruby script work without changing that code? It's an external dependency :/