WSL(Ubuntu):如何从bash终端在浏览器中打开localhost [英] WSL (Ubuntu): how to open localhost in browser from bash terminal

查看:1267
本文介绍了WSL(Ubuntu):如何从bash终端在浏览器中打开localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从WSL bash终端在(任何)浏览器中打开 http:// localhost

I am trying to open http://localhost in (any) browser from WSL bash terminal.

到目前为止,我已经尝试过:

So far I have tried:

  • How can I open Google Chrome from the terminal with the URL "localhost:3000"?
  • "Couldn't find a file descriptor referring to the console" on Ubuntu bash on Windows
  • How to mention C:\Program Files in batchfile

设置浏览器没有运气xdg-open的变量,它使用 / usr / bin / xdg-open响应 xdg-open http:// localhost :851:/ usr / bin / xdg-open:/ c /程序:未找到

No luck in setting up BROWSER variable for xdg-open, it responds to xdg-open http://localhost with /usr/bin/xdg-open: 851: /usr/bin/xdg-open: /c/"Program: not found.

我尝试使用 \转义\ ^ 使用%ProgramFiles(x86)%和ofcorse 程序文件(x86) 。每次都或多或少是相同的答案...关于如何设置在WSL中打开浏览器的工作流程的任何想法?

I have tried escaping with \ and ^. Using %ProgramFiles(x86)% and ofcorse "Program Files (x86)". More or less it is the same answer every time... Any ideas how to set a work flow for opening browser in WSL?

到目前为止,我最终得到了

So far I've ended up with:

/ c / Program\文件\ (x86\)/Google/Chrome/Application/chrome.exe localhost

但是我正在寻找更优雅的解决方案。

But I am looking for more elegant solution.

推荐答案

您可以调用Windows命令lin Bash中的e并使用Windows文件关联以默认的Windows浏览器打开URL。

You can invoke the Windows command line from Bash and use Windows file association to open URL with the default Windows browser.

要这样做,只需输入Bash:

To do so just type in Bash:

cmd.exe /C start http://localhost

在我的情况下,此加载 localhost 在Chrome中,请注意,完整的URL对于Windows决定执行操作是必需的。

In my case this loads localhost in Chrome, note that the full URL is necessary for Windows to decide what to do.

这与 open 在MacOS中的操作类似,因此直接使用该命令并使用别名可能会很有用。它还适用于其他类型的文件:

This is similar to what open does in MacOS, hence you may find useful to directly alias the command and use it also for other type of files:

# add this to .bash_aliases
open='cmd.exe /C start'

现在您可以打开URL open file.pdf 直接从WSL。

Now you can open URL or open file.pdf directly from WSL.

这篇关于WSL(Ubuntu):如何从bash终端在浏览器中打开localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆