Special Character issues

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
homescripter
Posts: 1
Joined: 28 Apr 2018 09:31

Special Character issues

#1 Post by homescripter » 28 Apr 2018 09:58

I found this forum searching through google and was hoping someone can help a self taught coder out.

I have a batch file that grabs the source code of a webpage so I can pull certain data out of it. It has been working for months perfectly. Well now I have a local page that has special character(s) that will not allow me to use the script as is.

Code: Select all

@if (@a==@b) @end /*
@echo off
setlocal

set "URL=http://127.0.0.1:99999/page/index.html#!/area/999...long string here containing just letters and numbers...999/site"

for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%url%') do (
	>>"D:\Data\Data.txt" echo %%I
)
I believe the issue is the # sign and/or the ! due to jscipt and can't find a workaround as of yet. I have tried %23, &num and countless other options with no success.

Any help would be greatly appreciated.

Thanks!

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Special Character issues

#2 Post by jfl » 29 Apr 2018 01:56

There's a missing double quote at the end of the last argument of the cscript command. It should be: ... "%URL%" '

With this, the # and ! characters make it through easily.
For example this test script:

Code: Select all

@if (@a==@b) @end /*
@echo off
setlocal

set "URL=http://127.0.0.1:99999/page/index.html#!/area/999...long string here containing just letters and numbers...999/site"

for /f "delims=" %%I in ('cscript /nologo /e:jscript "%~f0" "%URL%" %*') do (
  echo CSCRIPT output: %%I
)
exit /b
*/

var args=WScript.Arguments;
for (var i = 0, len = args.length; i < len; i++) {
  var arg = args.Item(i);
  WScript.Echo("arg[" + i + "] = " + arg);
}
WScript.Quit(0);
Results:

Code: Select all

C:\JFL\Temp>test ! % #
CSCRIPT output: arg[0] = http://127.0.0.1:99999/page/index.html#!/area/999...long string here containing just letters and numbers...999/site
CSCRIPT output: arg[1] = !
CSCRIPT output: arg[2] = %
CSCRIPT output: arg[3] = #

C:\JFL\Temp>
Of course, you must respect all batch syntax rules.
For example, if you have two exclamation points in your URL, and variable expansion is enabled, then the !section_of_your_url! will be expanded, probably to an empty string!
The workaround is to use !URL! instead of %URL% in this case.

Post Reply