Opening a URL with an equals in it - batch-file

I am looking to create a very simple batch file to open a URL. It's so simple I'm just usingstart URL.
The problem is that in the URL there are some '=' signs ie.context=user&overlay=node and this is stopping the batchfile from opening the full URL.
How can I stop this.
Kind regards
Matt

You should probably url-encode the equal signs to %3D - see for instance https://en.wikipedia.org/wiki/Percent-encoding.

& and = are specials characters in batch scripting. Just quote the URL and pass an empty string as the title like that :
#echo off
start "" "https://example.com/context=user&overlay=node"

Related

Add plus sign to batch file url

I have a batch file which opens a pop-up within a website. The website opens fine, but when I want to add a parameter with a plus character, +, it doesn't work!
The code looks like this:
#echo off
start "Chrome" chrome --app=https://website.com?phone=%1
However the %1 will be replaced with the incoming number but without the + before it.
I don't why that happens so I tried to add a plus manually.
#echo off
start "Chrome" chrome --app=https://website.com?phone=+%1
But that doesn't work either!
Does anyone have an idea how to add the + sign to the url?
The desired result should be:
https://website.com?phone=+3112345678
That's because + is the url encoding for space.
To encode a plus sign you have to use %2b.
But in batch-files the percent sign is also a special character, therefore it has to be escaped itself by another percent sign.
https://website.com?phone=%%2B555-123
And the url should be quoted, because when more than one get parameter is present, then these parameters are separated by & signs, that collides again with the special meaning in batch files for command separation.
start "Chrome" chrome --app="https://website.com?phone=%%2B%1&name=John"

How to capture user URL input and search on google in Batch?

I am making this simple project in which the program captures the user input and searches it up on google.
For example , if %variable% is the URL the user types, then
here is a "demo" of what I want:
start CHROME %variable%
Answer (Me)
I think I have an answer to my own question:
set /p urlinput=Search:
start CHROME %urlinput%
start CHROME google.com/search?q=%urlinput%*
I will be leaving this up in case people need to know the answer.
*You need to add Pluses between each word for the search to work
This works for me on Windows 10 for a search about javascript:
set /P URL_IN=""
< javascript
start chrome "https://www.google.com/search?q=%URL_IN%"
Where < javascript is the user input.
It is important to enclose the URL in quotes otherwise words get dropped after spaces.
Answer (Me)
I think I have an answer to my own question:
set /p urlinput=Search:
start CHROME %urlinput%
start CHROME google.com/search?q=%urlinput%*
I will be leaving this up in case people need to know the answer.
*You need to add Pluses beteen each word for the search to work

Open URL that contains umlaut with batch

I want to open an URL in chrome with a batch file. This works for normal URLs, but it doesn't for URLs with umlauts.
start chrome.exe https://trends.google.de/trends/explore?q=mähroboter
I cannot use "ae" as a replacement for "ä", as it will give me different results on Google Trends.
When I keep it like this, the URL in my browser changes to
https://trends.google.de/trends/explore?q=mA4hroboter
which again gives me the wrong results. It needs to be "ä".
I tried playing around with the file encoding. Currently UTF8 without BOM. I tried UTF8 with BOM, ANSI, converting to and fro. Nothing seemed to work. What can I do to make it work?
URLs must be URL encoded with percent-encoded bytes.
That means the German umlaut ä in a URL must be first UTF-8 encoded with the two bytes with the hexadecimal values C3 A4 and next percent-encoded resulting in %C3%A4 in the URL string:
https://trends.google.de/trends/explore?q=m%C3%A4hroboter
In a batch file a percent sign must be escaped with an additional percent sign to get it interpreted by Windows command processor as literal character and not
as beginning of a batch file argument reference as explained by help of command CALL output on running call /? in a command prompt window, or
beginning of a loop variable reference as explained by help of command FOR output on running for /? in a command prompt window, or
beginning / end of an environment variable reference as explained by help of command SET output on running set /? in a command prompt window.
So in the batch file must be used:
start chrome.exe https://trends.google.de/trends/explore?q=m%%C3%%A4hroboter

Batch file to launch XBMC URL

I've been trying to write a simple Windows batch file to open a video file on my Media PC. When you place a URL to a media file in the quotation marks after file: and hit enter the file opens on XBMC. This is what I have so far:
#echo off
set /P url=Enter video URL:
start http://xbmc:8080/jsonrpc?request={"jsonrpc":"2.0","method":"player.open",%%20"params":%%20{"item":{"file":""%url%""}}}
The webpage opens and the variable is substituted but my problem is that the quotation marks disappear. I've researched this and tried the backslash \, caret ^ and double quotes but none of these worked. A solution to this problem is greatly appreciated.
Also, I have around 10 minutes of experience with batch files so please be forgiving if the solution is simple!
Thanks!
In the same way that spaces have to be replaced with %%20, quotes need to be replaced with %%22. See this list for other substitutions - you'll be using the value from the "hx" column.
#echo off
set /P url=Enter video URL:
start http://xbmc:8080/jsonrpc?request={%%22jsonrpc%%22:%%222.0%%22,%%22method%%22:%%22player.open%%22,%%20%%22params%%22:%%20{%%22item%%22:{%%22file%%22:%%22%%22%url%%%22%%22}}}
You should wrap your entire URL in double quotes to have the inner double quotes escaped:
start "http://xbmc:8080/jsonrpc?request={"jsonrpc":"2.0","method":"player.open",%%20"params":%%20{"item":{"file":""%url%""}}}"
Hope this helps.

Windows batch file "start" command is not opening complete URL

I am creating a batch file in windows with the following command in it.
start https://abcd.com/command?username=user&password=pass&mode=desktop
I am expecting this to open default browser with this URL when running it. It does open the default browser, but the URL that was opened in the browser is actually truncated.
https://abcd.com/command?username=user
What should I give in the URL to make it posted completely?
& is a special character in batch scripting. Just quote the URL and pass an empty string as the title:
start "" "https://abcd.com/command?username=user&password=pass&mode=desktop"
You should be able to do this by inserting a caret before the ampersand:
https://abcd.com/command?username=user^&password=pass^&mode=desktop

Resources