Add plus sign to batch file url
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"
Read url of online-link(.url) with batch
There is no need to use the type
command; use input redirection (<
) to read the file and pass it into the find
command.
To capture the last line of the standard output of a command line and store it into a variable (LINE
), use a for /F
loop:
for /F "tokens=1* delims== eol=" %%I in ('^< "Craft The World.url" find "URL"') do set "LINE=%%J"
echo Last line: "%LINE%"
To process multiple lines of output, do that within the body of the loop, using the for
variable reference %%J
directly:
for /F "tokens=1* delims== eol==" %%I in ('^< "Craft The World.url" find "URL"') do (
echo Line string: "%%J"
)
The above approaches both split off the URL=
prefix by making use of the tokens
and delims
options of the for /F
command.
With your string URL=steam://rungameid/248390
, you can kind of misuse the ~
modifies of the for
variable reference %%J
:
for /F "tokens=1* delims== eol=" %%I in ('^< "Craft The World.url" find "URL"') do (
echo Line string : "%%J"
echo Last element: "%%~nxJ"
)
This works, because the /
becomes converted to the standard path separator \
, so steam://rungameid/248390
becomes steam:\\rungameid\248390
internally, whereof the last path element is extracted by the ~n
and ~x
modifiers. The other path modifiers do not return anything useful, because they work reliable only when no /
but only \
occur.
How can I echo a newline in a batch file?
echo hello & echo.world
This means you could define & echo.
as a constant for a newline \n
.
Turn on echo for a single command in a batch file
You can use a small macro (%+@%
), it will show the command and then executes it.
@echo off
call :define_macro
setlocal EnableDelayedExpansion
set var=content
%+@% ver
%+@% ver /?
%+@% echo %var% !var!
exit /b
:define_macro
(set \n=^^^
)
set ^"+@=for %%# in (1 2) do if %%#==2 (%\n%
setlocal EnableDelayedExpansion %\n%
for /F "tokens=1,*" %%1 in ("!time: =0! !argv!") do (%\n%
endlocal%\n%
echo %%1 Execute: %%2%\n%
endlocal%\n%
%%2%\n%
)%\n%
) ELSE setlocal DisableDelayedExpansion ^& set argv="
exit /b
Outputs:
14:04:08,05 Execute: ver
Microsoft Windows [Version 10.0.17134.1069]
14:04:08,05 Execute: ver /?
Displays the Windows version.VER
14:04:08,05 Execute: echo content !var!
content content
Edited: From the suggestions of sst, I removed the helper function, but to be able to use a custom and nice prefix, I decided against the echo on
inside the macro.
Related Topics
What Characters Must Be Escaped in an Http Query String
Table Row Won't Contain Elements with Position:Absolute
CSS Filter:Invert Not Working with Background-Color
Why Should One Add Id to Their HTML Tags
Dropdown with a Form Inside with Twitter-Bootstrap
How to Collapse/Expand a Div Within an Email? What Clients Support This
Flexbox on Ie11: Image Stretched for No Reason
Delay HTML5 :Invalid Pseudo-Class Until the First Event
Why Does a Diamond with a Questionmark in It Appear in My HTML
How Remove Border Around Image in CSS
Floating Elements Are Outside of Containing Blocks
"Compile" CSS into HTML as Inline Styles