Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Does %1 have limitation on certain characters  (Read 10762 times)

0 Members and 1 Guest are viewing this topic.

Frank

    Topic Starter


    Intermediate

    Thanked: 3
    Does %1 have limitation on certain characters
    « on: July 03, 2012, 10:55:28 PM »
    Hello
    I am using a batch file to launch a web page that contains '=' signs followed by numbers. I pass this URL to the batch file via a command line argument %1.
    eg:
    start "" /B %1 %2
    The problem is that the URL gets truncated just before the = sign.
    An example URL is http://www.tek-tips.com/threadminder.cfm?pid=287&page=1
    Is there something I can do about this.

    Frank

      Topic Starter


      Intermediate

      Thanked: 3
      Re: Does %1 have limitation on certain characters
      « Reply #1 on: July 04, 2012, 05:53:11 AM »
      I found a complicated solution.
      I encoded the '=' and '&' to strings 'equal' and 'and'. This now transfers correctly with the new strings.
      In the batch file I use substitution to restore the '=' and '&'.
      It seems to work.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Does %1 have limitation on certain characters
      « Reply #2 on: July 04, 2012, 08:50:59 AM »
      I believe you could also enclose the parameter variables in quotes.
      I was trying to dereference Null Pointers before it was cool.

      Salmon Trout

      • Guest
      Re: Does %1 have limitation on certain characters
      « Reply #3 on: July 04, 2012, 11:34:45 AM »
      The following are treated as parameter delimiters: space, tab, comma, semicolon, equals sign.

      If you pass the parameter with quotes like this

      mybatch.bat "http://www.tek-tips.com/threadminder.cfm?pid=287&page=1" "parameter 2"

      ... the batch script will receive the whole string OK but now you run into a START command syntax issue. If you use quotes you trigger the START "title" "parameter" syntax and you need to have a title string which can be null if you like thus the batch line becomes

      start /B "" %1 %2




      Frank

        Topic Starter


        Intermediate

        Thanked: 3
        Re: Does %1 have limitation on certain characters
        « Reply #4 on: July 06, 2012, 06:47:30 PM »
        Thank you for the idea of using the quotation marks.
        Unfortunately, I am using TCL/TK to generate the command line to launch my batch file with the command line argument of the URL. I am able to create the text with quotation marks, but, when it arrives in the batch file, the quotation marks end up being preceded with a '\' (ie it arrives as \"http://...etc....\").
        What I have been able to do is substitute ordinary letters for the symbols and then in the batch file reverse substitute that does work. This is how I reverse substituted in the batch file:

        setlocal enabledelayedexpansion
        set var=equal
        set url=!url:%var%==!
        echo !url!

        set var=and
        set url=!url:%var%=^&!
        echo !url!

        This substitutes 'equal' to '=' and 'and' to '&'.
        This does the job but I would like to do more substituting and would prefer to place the substituting into a loop. Is there a way to do that in an batch file?
        Thanks

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Does %1 have limitation on certain characters
        « Reply #5 on: July 06, 2012, 11:11:44 PM »
        in TCL you need to escape double quotes. I believe the string would, if inserted literally, look something like this:

        Code: [Select]
        "start /B \"\" \"%1\" \"%2\""
        I was trying to dereference Null Pointers before it was cool.

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Does %1 have limitation on certain characters
        « Reply #6 on: July 06, 2012, 11:27:02 PM »
        in TCL you need to escape double quotes. I believe the string would, if inserted literally, look something like this:

        Code: [Select]
        "start /B \"\" \"%1\" \"%2\""

        Correction: use curly braces:

        Code: [Select]
        {start /B "" "%1" "%2"}
        Sounds like you might be using curly braces and trying to escape the quotes, at the same time. (this the backslashes appear) You only need to escape curly braces, though.
        I was trying to dereference Null Pointers before it was cool.

        Frank

          Topic Starter


          Intermediate

          Thanked: 3
          Re: Does %1 have limitation on certain characters
          « Reply #7 on: July 06, 2012, 11:41:16 PM »
          No,
          start /B %1
          line is in the batch file.

          The TCL script that calls the batch file should look like this:
          exec trial1.bat \"${url}\" &
          or
          set url \"${url}\"
          exec trial1.bat $url &
          This produces a string enclosed by quotation marks, but, in the batch file it looks like \"string....\".

          Salmon Trout

          • Guest
          Re: Does %1 have limitation on certain characters
          « Reply #8 on: July 06, 2012, 11:59:37 PM »
          Unfortunately, I am using TCL/TK to generate the command line to launch my batch file with the command line argument of the URL.

          I am using a ladder perched on a chair standing on a table to kiss my girlfriend who is half way up the stairs...


          Frank

            Topic Starter


            Intermediate

            Thanked: 3
            Re: Does %1 have limitation on certain characters
            « Reply #9 on: July 07, 2012, 12:19:47 AM »
            Yes, I understand that I am going about it the long way around but my last question got lost.
            How do I place the following in a loop:

            setlocal enabledelayedexpansion
            set var=equal
            set url=!url:%var%==!
            echo !url!

            set var=and
            set url=!url:%var%=^&!
            echo !url!

            Thanks

            Salmon Trout

            • Guest
            Re: Does %1 have limitation on certain characters
            « Reply #10 on: July 07, 2012, 12:25:51 AM »
            How do I place the following in a loop:

            What is the source of the lines to be processed?

            Frank

              Topic Starter


              Intermediate

              Thanked: 3
              Re: Does %1 have limitation on certain characters
              « Reply #11 on: July 07, 2012, 12:59:57 AM »
              I have shown 2 sections above. I would like to do about 5.
              I am not sure what you mean by 'the source'
              Thanks

              Salmon Trout

              • Guest
              Re: Does %1 have limitation on certain characters
              « Reply #12 on: July 07, 2012, 01:15:33 AM »
              I am not sure what you mean by 'the source'

              I am not sure what you mean by 'in a loop'

              Loops in batch are implemented with the FOR command or by gotos. The FOR command processes a dataset which can be an explicit list

              for %%A in (cat dog owl horse) do (
                  echo Animal is %%A
                  )

              or using the /f switch a source of lines such as a file or the console output of a command or program:

              for /f %%A in (animals.txt) do (
                  echo Animal is %%A
                  )

              So what is the reason for doing it in a loop?

              [EDIT] I believe I see what you are getting at.... you want to cycle through all the substitutions... ?





              Frank

                Topic Starter


                Intermediate

                Thanked: 3
                Re: Does %1 have limitation on certain characters
                « Reply #13 on: July 07, 2012, 01:26:38 AM »
                Yes, that is the sort of loop I am looking for.
                The whole source I want convert into a loop is:

                set var=\"
                set url=!url:%var%=!
                echo !url!

                set var=equal
                set url=!url:%var%==!
                echo !url!%2

                set var=and
                set url=!url:%var%=^&!
                echo !url!

                set var=comma
                set url=!url:%var%=^,!
                echo !url!

                set var=semi
                set url=!url:%var%=^;!
                echo !url!

                set var=space
                set url=!url:%var%=^ !
                echo !url!

                The reason for placing this into a loop is to shorten the code, and so that I know how to do it in the future.
                Thanks

                Salmon Trout

                • Guest
                Re: Does %1 have limitation on certain characters
                « Reply #14 on: July 07, 2012, 01:51:08 AM »
                You could do something like this


                REM This can go at the start of the script
                setlocal enabledelayedexpansion
                REM Must escape quotes in dataset
                for %%A in (\^" equal and comma semi space) do (
                   set var=%%A
                   if !var!==\"    set url=!url:%var%=!
                   if !var!==equal set url=!url:%var%==!
                   if !var!==and   set url=!url:%var%=^&!
                   if !var!==comma set url=!url:%var%=^,!
                   if !var!==semi  set url=!url:%var%=^;!
                   if !var!==space set url=!url:%var%=^ !
                   )