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"
Related
I wanted to make a batch program to start all of my web browsers and open them to a websites saved on my computers local storage. Everything works correctly until the URL is copied into cmd and it changes the link.
start "" "Google Chrome" "file:///C:/Users/User/Desktop/Programming/Web%20Dev/Websites/PRP%20Website/index.html"
When I run this code the two places there is %20, only a 0 gets put into the cmd so the new code looks like this
start "" "Google Chrome" "file:///C:/Users/User/Desktop/Programming/Web0Dev/Websites/PRP0Website/index.html"
I do know I could change the folder name and the problem would be fixed, but I was hoping there would be a way to fix this problem with code and not the file names
The core problem is that cmd.exe is interpreting "%2" as the second parameter on the command line. Since there is no second parameter on the command line "%2" is replaced with nothing. This can be overcome by:
1) Replace "%20" with a SPACE " " character
2) Escape the "%" with another "%" character, resulting in "%%20".
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
I have made a shortcut for opening folders based on job numbers for work. It looks through the job directory for the job number and then opens that folder. Unfortunately, this fails when the folder name has a comma "," in it:
IF %JOBNUM%==!JOBTEST! %SystemRoot%\explorer.exe %%G
Where, for example:
%%G = X:\A12300-12399\A123456 - Job with, comma
Instead of opening the job folder, it just opens My Documents (which, I assume, is the default location for Explorer.
Is there a way to let it know that the comma is part of the folder name and not some sort of delimiter?
Try adding the path inside quotes like "path"
Batch files are essentially shell commands executed as a batch. Commands are delimited by space, "," , "=" etc. As shown Here
When you use a pathname with a delimiter, windows takes the first string to be the actual value and discards the rest. Using quotes is explicitly instructing the shell to treat everything inside the quotes as a single unit. That goes the same for %%G.
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"
I have a .bat file that opens a local file in a browser. The path to the local file contains spaces (not by my choice):
file:///N:/Users/Firstname%20Lastname/Placeholder%20Report%20Name.html
However, the browser changes this to:
file:///N:/Users/Firstname0Lastname/Placeholder0Report0Name.html
The %20 is replaced with 0 instead of , so the link does not work.
I've tried replacing file:/// with file:\\ and a different browser, but the result is the same. What am I missing? I can't change the name or path of the target file.
You have to escape the % with another one like this:
file:///N:/Users/Firstname%20Lastname/Placeholder%20Report%20Name.html
->
file:///N:/Users/Firstname%%20Lastname/Placeholder%%20Report%%20Name.html
Reason for that is the fact that %2 stands for the second argument, that got send to the batch file:
yourBat.bat first second
would result in your browser path beeing
file:///N:/Users/Firstnamesecond0Lastname/Placeholdersecond0Reportsecond0Name.html
as %2 gets substituted with the word second.
With another % added this will be escaped.