How to open a URL with cmd?

无人久伴 提交于 2020-12-04 20:01:44

问题


I already know that to open a webpage with the default browser you use: start www.google.com. However, I'm trying to open a URL that contains a '&' in it for example:

https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world

If I use:

start https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world

It will not work cause there is a &


回答1:


& is a special caractere in batch so if the URL contains a special caractere you just have to do it like this:

start "" "your url" 



回答2:


You have to escape the Ampersand (&) character with the ^ character in every occurrence of it.

start https://www.google.dz/?gws_rd=cr,ssl^&ei=rXc_WYq3Msy2abGXpugH#safe=off^&q=hello+world



回答3:


You can use URL shorteners.

For your link:

start [created link]



回答4:


If you have Linux you can try using these command

$links http://google.com

or

$elinks http://google.com/



回答5:


Powershell

By passing through powershell : powershell Start-Process <browser> <URL>.

If you don't specify browser, then URL is open in your default browser. Mine is Google Chrome, so i have added chrome. For internet explorer, it will be iexplorer and for Mozilla Firefox, this is firefox.

Examples from a CMD prompt :

powershell Start-Process chrome http://google.com/

or a little bit shorter :

powershell Start-Process http://google.com/ 

or even more shorter :

powershell start http://google.com

However, in your case, type in the one hand powershell command to goto powershell prompt. In the other hand, just type one of the following command line by specifying URL with "" in order to dodge the & effect as explained by jgmh above :

start "https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world"

or by chosing a specific browser such as firefox :

start firefox "https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world"

or else :

[System.Diagnostics.Process]::Start("firefox.exe","https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world")

Finally, type exit in order to quit the powershell prompt.

CMD


Using start command only

idris19's method is really handy !

This command line can also help you because you are able to indicate your browser : start <browser> <URL>.

As said before, URL is open in your default browser if none is specified.

For instance :

start http://google.com

or

start chrome http://google.com

But, in your case, don't forget to add "" to avoid & issue and mention your browser to not run URL in another cmd window :

start chrome "https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world"

You can add -incognito flag to goto an incognito browser if necessary :

start chrome "https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world" -incognito

Using windows explorer

Furthermore, you can use windows explorer as following : explorer <URL>. It always will open your URL in the default browser.

Example :

explorer http://google.com

As previously mentioned, don't forget the double quotes in your case due to & special character :

explorer "https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world"

Note : Tested on Windows 10 64bits.

P.S : Please, don't hesitate to edit my answer because i probably made grammatical mistakes due to my low english level. Thanks ! Best regards :-)




回答6:


First provide the full path to the browser application file and then the complete link like this:

start "C:\Path\To\Browser.exe" "http://WebsiteURL.com"



回答7:


Try one of these command lines:

powershell -command "start 'https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world'"

or

start "" "https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world"

or even this one:

explorer "https://www.google.dz/?gws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world"



回答8:


He understands that the "&" is an operator. Use the link reducer: https://goo.gl/




回答9:


When I tried the same, it worked for me only by typing :

C:\start https://www.google.dz/?ws_rd=cr,ssl&ei=rXc_WYq3Msy2abGXpugH#safe=off&q=hello+world

in the Command Prompt.



来源:https://stackoverflow.com/questions/44513063/how-to-open-a-url-with-cmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!