Batch File Problem - Properly Handling the % symbol - Microsoft Windows

This is a discussion on Batch File Problem - Properly Handling the % symbol - Microsoft Windows ; I've written a batch file that takes a string as input, and is supposed to launch the Opera browser after parsing the incoming string. The synax to run the batch file is: runme.bat "opera://http://www.mywebsite.com?var1=a&var2=b&var3=c In order to parse the string, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Batch File Problem - Properly Handling the % symbol

  1. Batch File Problem - Properly Handling the % symbol

    I've written a batch file that takes a string as input, and is
    supposed to launch the Opera browser after parsing the incoming
    string. The synax to run the batch file is:

    runme.bat "opera://http://www.mywebsite.com?var1=a&var2=b&var3=c

    In order to parse the string, I need to do two things.
    1. replace the ampersand (&) characters with %25
    2. strip off "opera:// from the front, and the trailing quote symbol
    from the end.

    Here's the syntax of my script:

    set _url=%1
    set _url=%_url:&=%25%
    set _url=%_url:~9,-1%
    echo %_url%
    start "" c:\progra~1\opera\opera.exe %_url%

    Line one reads in the full string parameter.
    Line two is supposed to replace the ampersand character with %25 ....
    the URL encoded version of that character.
    Line three strips off the leading and trailing characters I don't
    need.
    Line four echos the result for review
    Line five starts up Opera with the parsed URL as its parameter.

    My problem is that the ampersand substitution doesn't work.
    Everything else seems to work fine. How do I properly escape the %
    symbol in my replacement string (%25) so that this will work? I've
    tried ^%25, %%25, and all sorts of other combinations, but nothing
    seems to work.

    Thanks in advance.


  2. Re: Batch File Problem - Properly Handling the % symbol

    On May 24, 3:30 pm, uptown wrote:
    > I've written a batch file that takes a string as input, and is
    > supposed to launch the Opera browser after parsing the incoming
    > string. The synax to run the batch file is:
    >
    > runme.bat "opera://http://www.mywebsite.com?var1=a&var2=b&var3=c
    >
    > In order to parse the string, I need to do two things.
    > 1. replace the ampersand (&) characters with %25
    > 2. strip off "opera:// from the front, and the trailing quote symbol
    > from the end.
    >
    > Here's the syntax of my script:
    >
    > set _url=%1
    > set _url=%_url:&=%25%
    > set _url=%_url:~9,-1%
    > echo %_url%
    > start "" c:\progra~1\opera\opera.exe %_url%
    >
    > Line one reads in the full string parameter.
    > Line two is supposed to replace the ampersand character with %25 ....
    > the URL encoded version of that character.
    > Line three strips off the leading and trailing characters I don't
    > need.
    > Line four echos the result for review
    > Line five starts up Opera with the parsed URL as its parameter.
    >
    > My problem is that the ampersand substitution doesn't work.
    > Everything else seems to work fine. How do I properly escape the %
    > symbol in my replacement string (%25) so that this will work? I've
    > tried ^%25, %%25, and all sorts of other combinations, but nothing
    > seems to work.
    >
    > Thanks in advance.



    By the way, the command line should have had a trailing quote:

    runme.bat "opera://http://www.mywebsite.com?var1=a&var2=b&var3=c"


  3. Re: Batch File Problem - Properly Handling the % symbol

    On May 24, 3:30 pm, uptown wrote:
    > I've written a batch file that takes a string as input, and is
    > supposed to launch the Opera browser after parsing the incoming
    > string. The synax to run the batch file is:
    >
    > runme.bat "opera://http://www.mywebsite.com?var1=a&var2=b&var3=c
    >
    > In order to parse the string, I need to do two things.
    > 1. replace the ampersand (&) characters with %25
    > 2. strip off "opera:// from the front, and the trailing quote symbol
    > from the end.
    >
    > Here's the syntax of my script:
    >
    > set _url=%1
    > set _url=%_url:&=%25%
    > set _url=%_url:~9,-1%
    > echo %_url%
    > start "" c:\progra~1\opera\opera.exe %_url%
    >
    > Line one reads in the full string parameter.
    > Line two is supposed to replace the ampersand character with %25 ....
    > the URL encoded version of that character.
    > Line three strips off the leading and trailing characters I don't
    > need.
    > Line four echos the result for review
    > Line five starts up Opera with the parsed URL as its parameter.
    >
    > My problem is that the ampersand substitution doesn't work.
    > Everything else seems to work fine. How do I properly escape the %
    > symbol in my replacement string (%25) so that this will work? I've
    > tried ^%25, %%25, and all sorts of other combinations, but nothing
    > seems to work.
    >
    > Thanks in advance.



    Solved my own problem by putting quotes around the parameter and not
    bothering with any substitution.

    set _url=%1
    set _url="%_url:~9,-1%"
    echo %_url%
    start "" c:\progra~1\opera\opera.exe %_url%


+ Reply to Thread