-1

pre: I already looked at this, but it does not work in my case. How do I escape ampersands in batch files?

In a (Win10) batch file for cmd, I get passed some arguments and I want to send them via WGET.exe %set_var% to my web server.

What i need is the resulting string for WGET in a set-variable which should read like:

<ipaddress&port>?p1=%1%&p2=%2%&p3=%3% ...

I tried to escape the & with ^ and wrote ^& everywhere the & should appear like this line:

set zzz="%wget_addr%?p1=%1%^&p2=%2%^&p3=%3%^&p4=%4%^&p5=%5%^&date=%date%^&time=%time%"

wget.exe %zzz%

But it does not work. The result is just a concettenation of the arguments, but my variables are missing.

What do I miss to code? Thanks a lot!

jwka
  • 115
  • 7
  • Since `<`, `>`, `&` and `%` are all special characters in batch, please show us precisely the command you wish to generate, including typical values for each parameter (obfuscated if necessary) – Magoo Dec 15 '22 at 12:15
  • Command line parameters are referenced as `%1` etc, not `%1%`. So your code tries to concatenate the first parameter (`%1`) plus a variable named `%^&p2=%`, then a literal 2 then the variable `%^&p3=` etc. – Stephan Dec 15 '22 at 12:24
  • (by the way: your `&` are safe within quotes - no need to escape them) – Stephan Dec 15 '22 at 12:27

1 Answers1

0

Thanks Stephan, I guess the %1% was my (major) error. I always thought if one wants to use the content of a var, the trailing % is needed, which obviously is only needed when accessing a variable.

jwka
  • 115
  • 7
  • the parameters (arguments) are not "normal environment variables" - they work different (see `call /?` for what you can do with them ("Modifiers")). – Stephan Dec 15 '22 at 12:33