Table of Contents
- Open a simple URL with START Command
- Open a URL that contains an ampersand & with the START command
- Ways to open a Website containing an ampersand (&)
- Way 1: By adding a caret character ( ^ ) before each & ampersand.
- Ways 2: Using Empty Quotes before website URL and query string
- Ways 3: Using Powershell to open website URL using double quotes
START Command is a helpful command that enables a user to open a separate new window from within the Windows Command line. Its general syntax is:
- title: Sets the Command Prompt window title.
- /d path: Specifies the startup directory.
- command: Specifies the command or program or web URL to start.
- parameter: Sets parameters for the command or program and many more. (source)
Open a simple URL with START Command
Using the Start Command, we can easily open the website URL in the following format:
This will open the website in the default web browser.
Open a URL that contains an ampersand & with the START command
However, if you try to open a website that contains a query string and a special character, it will cause an error. For demonstration, I am trying to access the below URL containing the special character(&) in the string.
After you have entered this command into the Command Prompt and pressed Enter, you will find that the website page will give the result up to "https://www.google.com/search?q=tricks" and the remaining &source=hp will give an error with the message that is shown below.
Screenshot of the error message:
In this case, everything that comes after the ampersand (&) will be read as its separate command which will result in an error.
This is due to the fact that the Command Prompt will consider & to be a special character. So in this case everything that comes after the ampersand (&) will be read as its separate command which will result in an error.
Other special characters that can be entered into the Command Prompt include # $ & + , / : ; = ? @ [ ] and so on. In the event that you use any of these characters in the command line, it will not treat the string as a normal one. Therefore, the primary focus of our work will be to convert the URL to a normal string.
Ways to open a Website containing an ampersand (&)
There are 3 ways for it. Let's look at each of them in-depth.
Way 1: By adding a caret character ( ^ ) before each & ampersand.
& is a special character in bash; therefore, if the URL contains a special character, you must prefix each & with ^.
This denotes that the character is to be treated like any other character, and it takes away any special meaning it may have previously held.
Multiple & ampersands in URL
Take note that if you have multiple & ampersands, you need to add the ^ sign just before each of them as shown below
Ways 2: Using Empty Quotes before website URL and query string
When using the Start Command, we are required to give the dummy argument as the first argument. You can simply give it an empty string.
START "" "www.google.com/search?q=tricks&source=hp"
Also do not forget to double-quote the web URL.
Ways 3: Using Powershell to open website URL using double quotes
In Powershell, you do not have to do anything. Just enclose it in double quotes.
In Powershell, there are additional methods for opening web URLs with query strings and ampersands. This method employs the start-process command.
In this way, we can successfully open a URL that contains an ampersand & with the START command